Tuple Functions Of Python

 Tuples, like Python lists, are a common data type that allows you to store values in a sequential order. They could be handy in circumstances when you want to communicate data with someone but don't want them to be able to change it. They can still use the data values, but no changes are made to the original data.

Python tuples are covered in depth in this tutorial:


You'll discover how to initialise tuple functions in python. Through examples, you'll understand how tuples are immutable; you'll also learn how a tuple varies from a Python list.

Then you'll see tuple operations like slicing, multiplying, concatenating, and so on;

Some built-in tuple functions are useful, and you'll examine some of the most significant ones in this section.

Finally, you'll see that tuples can have several values assigned to them at the same time.

As previously stated, you may use this Python data structure to store an immutable (or unchangeable) and ordered series of things.


Tuples are started with () brackets instead of [] brackets like lists. That implies all you have to do to make one is perform the following:


print(type(cake)) class 'tuple'> cake = ('c','a','k','e')

Keep in mind that type() is a built-in function that can be used to determine the data type of a given.


Both homogeneous and heterogeneous values can be stored in a tuple. However, keep in mind that once you've defined your values, you won't be able to edit them:

mixed_type = ('C',0,0,'K','I','E')

for i in mixed_type:
    print(i,":",type(i))
C : <class 'str'>
0 : <class 'int'>
0 : <class 'int'>
K : <class 'str'>
I : <class 'str'>
E : <class 'str'>
# Try to change 0 to 'O'
mixed_type[1] = 'O'
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-16-dec29c289a95> in <module>()
----> 1 mixed_type[1] = 'O' # Trying to change 0 to 'O'


TypeError: 'tuple' object does not support item assignment

Comments

Popular posts from this blog

Unleashing Creativity: The Latest Frontier of Animation AI

Tanh Activation Function

Unveiling the Hidden Gems: Exploring Data Mining Functionality