Python Interview Questions
  • Python - Tuples
    1.Consider the tuple tuple1=("A","B","C" ), what is the result of the following operation tuple1[-1]?
    A) "A"
    B) "C"
    C) "B"

    Answer: "C"

    Explanation:  The index -1 corresponds to the last element of the tuple.
    2. Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation A[1]:
    A) ((11,12), [21,22])
    B) (11,12)
    C) [21,22]

    Answer: [21,22]

    Explanation: The index 1 corresponds to the second element in the tuple, which contains another list.
    3. Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation A[0][1]:
    A) 21
    B) 11
    C) 12

    Answer: 12

    Explanation: A[0] corresponds to the first nested tuple; we then access the second element of the tuple using the index 1 i.e A[0][1].
    4. What is the result of the following: len(("disco",10))
    A) 2
    B) 6
    C) 5

    Answer: 2

    Explanation: There are 2 elements in the tuple so the function len returns 2

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