Loading...

Python Programming: The Complete Guide to Learn Python for Data Science, AI, Machine Learning, GUI and More With Practical Exercises and Interview Questions by Ayden Nicholas

Python Programming: The Complete Guide to Learn Python for Data Science, AI, Machine Learning, GUI and More With Practical Exercises and Interview Questions by Ayden Nicholas

Author:Ayden, Nicholas [Ayden, Nicholas]
Language: eng
Format: epub, azw3
Published: 2019-11-07T16:00:00+00:00


Indexing, trimming and other tuple operations

Access to tuple elements, element extraction and operations are performed analogously to strings. Let's look at several examples:

>>> b = (3, 4, 5, 'a')

>>> b [0]

3

>>> b [-1]

'to'

>>> b [0: 3]

(3. 4. 5)

>>> t = ('the', 'tuples', 'are', 'immutable')

>>> t [0]

'the'

>>> t [1] = 'lists'

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: 'tuple' object does not support item assignment

The static or immutable characteristic of the tuples is observed, as are the strings. We can include tuples within tuples and concatenate and repeat them, such as string,

>>> b = (3, 4, 5, 'a')

>>> c = (b, 2)

>>> b + c

(3, 4, 5, 'a', (3, 4, 5, 'a'), 2)

>>> 3*b

(3, 4, 5, 'a', 3, 4, 5, 'a', 3, 4, 5, 'a')



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.