Python Programming - Console Input/Output

Exercise : Console Input/Output - General Questions
  • Console Input/Output - General Questions
21.
What will the end parameter in the print() function do?
Sets the output separator between arguments
Sets the end character at the end of the printed string
Controls the formatting of the printed string
Defines the width of the printed string
Answer: Option
Explanation:
The end parameter in print() sets the end character that will be printed at the end of the string.

22.
How can you remove leading and trailing whitespaces from a string?
str.trim()
trim(str)
str.strip()
remove_whitespaces(str)
Answer: Option
Explanation:
The strip() method in Python is used to remove leading and trailing whitespaces from a string.

23.
How can you check if a string ends with a specific suffix?
str.ends_with(suffix)
endswith(str, suffix)
str.endswith(suffix)
check_suffix(str, suffix)
Answer: Option
Explanation:
To check if a string ends with a specific suffix in Python, you can use the endswith() method.

24.
How can you print a formatted string with variable values?
print("Value is: " + variable)
print("Value is:", variable)
format_print("Value is: {}", variable)
print("Value is: %s" % variable)
Answer: Option
Explanation:
Using a comma in the print() function allows you to print a formatted string with variable values in Python.

25.
How can you read a boolean value from the console?
bool(input())
read_boolean()
input().to_bool()
bool(input().lower() == 'true')
Answer: Option
Explanation:
To read a boolean value from the console in Python, you can compare the input (converted to lowercase) with the string 'true'.