Python Programming - Console Input/Output

Exercise : Console Input/Output - General Questions
  • Console Input/Output - General Questions
6.
How can you clear the screen in a Python console application?
console.clear()
os.clear()
clear()
os.system("clear")
Answer: Option
Explanation:
You can use os.system("clear") to clear the screen in a Python console application.

7.
What is the purpose of the sys.stdin stream?
Reading input from the console
Writing output to the console
Standard error input
Redirecting output to a file
Answer: Option
Explanation:
sys.stdin is the standard input stream in Python, used for reading input from the console.

8.
Which of the following is used to format the output?
format()
print_format()
string.format()
f-string
Answer: Option
Explanation:
In Python, f-string is used for formatting output by embedding expressions inside string literals.

9.
How can you convert a string input from the console to an integer?
int(input())
convert_int(input())
input().to_int()
parse_int(input())
Answer: Option
Explanation:
To convert a string input to an integer in Python, you can use int(input()).

10.
What will happen if you try to concatenate a string and an integer using the + operator?
Error: Cannot concatenate string and integer
The integer will be converted to a string and concatenated
The string will be converted to an integer and concatenated
The program will terminate
Answer: Option
Explanation:
In Python, attempting to concatenate a string and an integer using + will result in a TypeError.