Print('Length of a FruitsTP = ', len(FruitsTP)) #Calculating Length of a using len() Method Print('Sum of all items in a tp = ', sum(tp)) #Finding Sum of all item in a using Sum() Method FruitsTP = ('Apple', 'Orange', 'Banana', 'Kiwi', 'Grape', 'Blackberry') In the below program, we are applying all the Tuple methods. And the count function counts the total number of times the specified value is repeated. The sum function calculates the sum of all items inside the given one. The index function returns the index position of a specified value. The Len method finds or calculates the Length or Number of items, and the sorted method helps to sort the elements in ascending order. The min function helps us to find the Smallest or minimum item and the max function finds the Largest item or largest item. The tuple() method helps to convert the String or Lists into Tuple. Since List is mutable, we successfully changed the value from 5 to 14. In the Third statement, We assigned a new value at position, which is List inside it. Within the Second statement, We assigned a new value to this inside another at index position one.Īlthough it is a Nested tuple, the output throws a Type Error because it is immutable. Since it is immutable, the output is throwing a Type Error. Let’s see what happens when we do that.Īnalysis: Within the First statement, We assigned a new value at index position two. It won’t allow altering the tuple items inside it.
0 Comments
Leave a Reply. |