Python Print Function MCQS

Q. What data type does input() return?

A
int
B
str
C
float
D
Depends on what the user types
Solution:

Input() always returns a string in Python 3.

Q. Which statement reads an integer from the user?

A
int(input())
B
input(int)
C
input().int()
D
integer(input())
Solution:

Wrap input() in int() to convert the string.

Q. What is the purpose of the argument in input("Name: ")?

A
Default value
B
Prompt message shown to the user
C
Maximum length
D
Variable name
Solution:

The argument is the prompt displayed before reading input.

Q. The user enters 5 and 5. What does print(input() + input()) show?

A
10
B
55
C
Error
D
5 5
Solution:

 Both inputs are strings, so + concatenates them.

Q. Which code converts the input "1 2 3" into [1, 2, 3]?

A
list(input())
B
input().split()
C
list(map(int, input().split()))
D
int(input().split())
Solution:

split() creates a list of strings; map(int, …) converts each

Q. What happens when int(input()) receives "abc"?

A
Returns 0
B
Returns None
C
Raises ValueError
D
Returns "abc"
Solution:

Non-numeric text cannot be converted to int.

Q. What does input().split(",") return for "a,b"?

A
"a b"
B
["a", "b"]
C
("a", "b")
D
("a", "b")
Solution:

split(“,”) breaks the string at commas into a list.

Q. Which module reads a password without displaying it?

A
secret
B
getpass
C
hidden
D
os.password
Solution:

getpass.getpass() disables echo while typing.

Entri PDF Icon

Get Question Bank

Strengthen Your Practice with our comprehensive question bank.