This will result in TypeError.Likewise, nested tuples are accessed using nested indexing, as shown in the example below. Trying to access an element outside of tuple (for example, 6, 7.) will raise an Indeċrror.The index must be an integer so we cannot use float or other types. IndexingWe can use the index operator to access an item in a tuple where the index starts from 0.So, a tuple having 6 elements will have indices from 0 to 5. Mytuple = ('hello')print(type(mytuple)) # Creating a tuple having one elementmytuple = ('hello',)print(type(mytuple)) # Parentheses is optionalmytuple = 'hello',print(type(mytuple)) # Access Tuple ElementsThere are various ways in which we can access the elements of a tuple.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |