TypeError occurs while statement 2 is running. Give reason. How can it be corrected?
>>> tuple1 = (5) #statement 1
>>> len(tuple1) #statement 2
Answers
Answered by
5
to make a tuple you need to give ot more than one options inside the brackets
example > tuple1 = (5,6)
len(tuple1)
hope it helps you
Answered by
0
The correct statement will be:
>>> tuple1 = (5,) #comma after 5 to declare that this is a tuple
>>> len(tuple1)
- The 'statement 1' is making a variable, tuple1 which is of 'int' information type.
- The 'statement 2' is checking for the length of the variable, however, the contention passed is an 'int' information type.
- The 'len()' capacity can return the length just when the article is a grouping or a collection. This is the justification behind the TypeError.
- The error can be corrected by adding one comma after '5' in statement 1, as this will make a tuple and as a tuple is a collection, 'len()' capacity won't return an error.
Similar questions
Science,
5 months ago
History,
5 months ago
Hindi,
5 months ago
Computer Science,
10 months ago
India Languages,
10 months ago
Math,
1 year ago