Computer Science

What would following statements print? Given that we have tuple= ('t', 'p', 'l')

  1. print("tuple")
  2. print(tuple("tuple"))
  3. print(tuple)

Python Tuples

5 Likes

Answer

  1. print("tuple") ⇒ tuple
    It will simply print the item inside the print statement as it is of string type.
  2. print(tuple("tuple")) ⇒ it will throw error.
    TypeError: 'tuple' object is not callable
    This is because the variable "tuple" is being used to define a tuple, and then is being used again as if it were a function. This causes python to throw the error as now we are using tuple object as a function but it is already defined as a tuple.
  3. print(tuple) ⇒ ('t', 'p', 'l')
    It will return the actual value of tuple.

Answered By

4 Likes


Related Questions