Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
26.
How can you align text to the right in a Python console output?
Answer: Option
Explanation:
Using the f-string format
{text:>10}
aligns the text to the right within a 10-character wide space.
27.
How can you read a line of text from the console and split it into words?
Answer: Option
Explanation:
To read a line of text from the console and split it into words, you can use
input().split()
.
28.
How can you print a multiline string?
Answer: Option
Explanation:
To print a multiline string in Python, use newline characters (
\n
) to separate lines within a single print()
statement.
29.
How can you prompt the user for input and convert it to an integer in a single line?
Answer: Option
Explanation:
To prompt the user for input and convert it to an integer in a single line, use
int(input("Enter an integer: "))
.
30.
How can you check if a string contains only alphabetic characters?
Answer: Option
Explanation:
The
isalpha()
method is used to check if a string contains only alphabetic characters in Python.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers