Python Data Types Interview MCQ Questions and Answers 2

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on the basics of Python Data Types and Variables. This practice test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Python basics.

Go through Python Theory Notes on Data Types before attempting this test.



1) What is the output of the given Python program with data types.
carrots = 5
carrots = 5.0
carrots = 'beetroots'
print(carrots)
A) 5
B) 5.0
C) beetroots
D) Compiler error
Answer [=]
C
Explanation: As Python language is a dynamically typed, you can assign any type of data to the same variable.
2) What is the output of the below Python program?
pen=10;
pencil=20.5
sum = pen + pencil
print(sum)
A) 30
B) 10
C) 30.5
D) TypeError: Unsupported operand type(s) for +
Answer [=]
C
3) What is the output of the below Python code snippet?
bananas=5.0e2
print(bananas)
A) 500.0
B) 500
C) bananas
D) TypeError or Compiler error
Answer [=]
A
Explanation: A floating point numbers can use "e" or "E" notation to represent exponentials.
4) What is the output of the given Python code snippet with floating point numbers?
apples=10e3
print(apples)
A) 1000.0
B) 1000
C) 10e3
D) 10E3
Answer [=]
A
5) Can you use E or Exponential notation to represent integers in Python?
A) NO
B) YES
C) --
D) --
Answer [=]
A
Explanation: No, you can not use E or Exponential notation with integers. Even if you use, the number will be treated as a floating point number only.
6) What is the output of the below Python code snippet with floating point and imaginary numbers?
ducks = 10e2+20e1j
print(ducks)
A) 1000+200j
B) (1000+200j)
C) 1000.0+200.0j
D) (1000.0+200.0j)
Answer [=]
B
7) What is the output of the below Python code snippet with floating point and imaginary numbers?
ducks = 10.0 + 20.0j
print(ducks)
A) 10+20j
B) (10+20j)
C) 10.0+20.0j
D) (10.0+20.0j)
Answer [=]
B


8) Imaginary numbers in Python suppress decimal notation if it can be converted to Integer. State TRUE or FALSE.
A) TRUE
B) FALSE
C) --
D) --
Answer [=]
A
Explanation: True
9) What is the output of below Python program with String?
dog_name = """Tomy
Tomi"""
print(dog_name)
A) Tomy Tomi
B)
Tomy
Tomi
C)
""Tomy
Tomi""
D) TypeError or Compiler Error
Answer [=]
B
Explanation: You can use Triple Double Quotes or Triple Single Quotes to create multiline Strings or comments.
10) State TRUE or FALSE. A Multiline string when not assigned to any variable will be treated as text under multi-line comments.
A) TRUE
B) FALSE
C) --
D) --
Answer [=]
A
Explanation:
'''
Hi Python
Hellor Python
Hi ExamTray
'''
11) In Python language you can use Single Quote and Double Quote interchangeably. State TRUE or FALSE.
A) TRUE
B) FALSE
C) --
D) --
Answer [=]
A
Explanation: True
12) What is the output of the given Python code snippet?
def count_ducks():
    print("Ducks 10")

    
print(count_ducks())
A)
Ducks 10
B)
Ducks 10
None
C)
None
D)
None
Ducks 10
Answer [=]
B
Explanation: Default return type is "None" in Python. It is something like "null" in Java language.