Python Programming - Console Input/Output

Exercise : Console Input/Output - General Questions
  • Console Input/Output - General Questions
36.
How can you remove all occurrences of a specific character from a string?
remove_char(string, 'x')
string = string.replace('x', '')
string.remove('x')
remove_occurrences(string, 'x')
Answer: Option
Explanation:
To remove all occurrences of a specific character from a string, use the replace() method.

37.
How can you check if a string is a valid email address?
check_email(str)
str.isemail()
validate_email(str)
re.match(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$', str)
Answer: Option
Explanation:
To check if a string is a valid email address, you can use a regular expression pattern with re.match().

38.
How can you print the ASCII values of all characters in a string?
for char in string: print(ord(char))
ascii_print(string)
print(ascii_values(string))
print(ascii(string))
Answer: Option
Explanation:
To print the ASCII values of all characters in a string, use a loop to iterate through each character and print its ASCII value using ord().

39.
How can you read multiple integers from the console and store them in a list?
int_list = input().to_list()
list(map(int, input().split()))
read_integers_list()
input().parse_int()
Answer: Option
Explanation:
To read multiple integers from the console and store them in a list, use list(map(int, input().split())).

40.
How can you format a floating-point number with a specific number of decimal places?
format_float(number, 2)
round(number, 2)
format(number, ".2f")
decimal_format(number, 2)
Answer: Option
Explanation:
To format a floating-point number with a specific number of decimal places, use format(number, ".2f").