In this article, we will try to understand python tuple with the help of two questions. one is ‘Which of the following is a python tuple?’ and in second one we need to find where python tuple will not be created.
Q1. Which of the following is a Python tuple?
A. | t1=tuple(357) |
B. | t1={3,5,7} |
C. | t1=[1,3,4,5] |
D. | t1=(3,5,7) |
Q2. Which of the following is not a python tuple ?
A. | T1=tuple(357) |
B. | S1={3,5,7} T1=tuple(S1) |
C. | L1=[3,5,7] T1=tuple(L1) |
D. | S=”Tuple” T1=tuple(S) |
Explanation Q1
Option A : tuple is a function which can convert list, set, string to tuple. But this is not application for numbers. So, when we try to create tuple by numbers, this will give error.
Option B : We create set using { } , so we created set here not tuple. It’s again not a tuple.
Option C : We create list using [ ] , so we created list here not tuple. It’s again not the right choice.
Option D : We create tuple using ( ) , so this is the right choice for creating a tuple.
Explanation Q2
Option A : tuple is a function which can convert list, set, string to tuple. But this is not application for numbers. So, when we try to create tuple by numbers, this will give error. In this case, we are not able to create a tuple, so it’s right choice.
Option B : We created a set named S1. But in the next line we used tuple method to convert the set into tuple. So, in this case we end up creating a tuple.
Option C : We created a list named L1. But in the next line we used tuple method to convert the list into tuple. So, in this case we end up creating a tuple.
Option D : We created a String named S. But in the next line we used tuple method to convert the string into tuple. So, in this case we end up creating a tuple.
If you have any doubt please comment below or Contact us and we will be happy to help .
To learn Python check out this .
Check out our courses :here