Python Interview Questions
  • Python - Data Types
    1. What is the type of the following: 1
    A) float
    B) int
    C) str

    Answer: int

    Explanation: As there is no decimal, the number is of type int
    2. What is the type of the following "7.1"
    A) float
    B) int
    C) str

    Answer: str

    Explanation: The type is string
    3. What is the result of the following code segment: int(12.3)
    A) 12.3
    B) 12
    C) 13

    Answer: 12

    Explanation: In Python, if you cast a float to an integer, the conversion truncates towards zero.
    4. What is the result of the following code segment: int(True)
    A) 1
    B) 0
    C) error

    Answer: 1

    Explanation: When you cast a boolean True to an integer you get a 1
    5. What do you call a value that doesn’t have decimal values?
    A) A number
    B) An integer
    C) A string

    Answer: An integer
    6. What do you call a value that does have decimal values?
    A) A float
    B) A number
    C) An integer

    Answer: A float
    7. What data type can only have either a value of True or False?
    A) A string
    B) A boolean
    C) An integer

    Answer: A boolean
    8. What code would turn the string “1” into an integer?
    A)str(1)
    B) int("1")
    C) float("1")

    Answer: int("1")
    9. What character begins a single line comment?
    A)'''
    B) //
    C) #

    Answer:#
    10. What do we call it when we convert from one data type to another?
    A)casting
    B) converting
    C) changing

    Answer:casting
    11. What is the datatype of np.nan?
    A) int
    B) float
    C) str
    D) None

    Answer: float
    12. Which of the following numbers is NOT a float?
    A) 1.5
    B) 2.333333
    C) 0.0
    D) 0

    Answer: 0

    Explanation:0 on its own is an int. 0.0 however, is a float.
    13. What values can the Boolean data type hold?
    A) Integers, fractions, complex numbers
    B) Unicode characters
    C) True or False values
    D) Any other data type

    Answer: True or False values
    14. WWhat does it mean that Python is a dynamically-typed language?
    A) Variables in python can implicitly change to other types when comparing. For examples you can compare a string "2" and the number 2 using ==.
    B) Python variables can be assigned to different types and changes types at will.
    C) Python is a more efficient language than C++
    D) All of the above

    Answer: Python variables can be assigned to different types and changes types at will.

    Explanation: Dynamic-typing just refers to the ability for variables to flexibly learn their types during assignment.

  • Apply for an intership with Datai Analytics by filling your email, name and phone number