6
Question Question 6
What would following statements print? Given that we have tuple= ('t', 'p', 'l')
- print("tuple")
- print(tuple("tuple"))
- print(tuple)
Answer
- print("tuple") ⇒
tuple
It will simply print the item inside the print statement as it is of string type. - 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. - print(tuple) ⇒
('t', 'p', 'l')
It will return the actual value of tuple.