Uses Of Tuple Functions In Python

 Tuples are used to store multiple particulars in a single variable.

Tuple is one of 4 erected-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different rates and operation.
A tuple is a collection which is ordered and incommutable.

Tuples are written with round classes.

Example: thistuple = (“apple”, “banana”, “cherry”)

(print this tuple)

Tuple Particulars
Tuple particulars are ordered, incommutable, and allow indistinguishable values.

Tuple particulars are listed, the first item has indicator (0), the alternate item has indicator (1) etc.

Ordered
When we say that tuples are arranged, it means that the particulars have a outlined order, and that order won’t modify.

Incommutable
Tuples are incommutable, meaning that we can not change, add or remove particulars after the tuple has been created.

Allow Duplicates

Since tuples are indexed, they can have items with the same value:

example: this tuple = (“apple”, “banana”, “cherry”, “apple”, “cherry”)
print(this tuple)

Tuple Length

To determine how numerous particulars a tuple has, use the len () function:

Example: Print the number of items in the tuple:

this tuple = (“apple”, “banana”, “cherry”)
print(len(this tuple))

Make A Tuple With One Item

To produce a tuple with only one item, you have to add a comma after the item, else Python won’t fete it as a tuple.

Example: One particular tuple, remember the comma:

this tuple = (“apple”,)
print(type(this tuple))

#NOT a tuple
this tuple = (“apple”)
print(type(this tuple))

Tuple Items — Data Types

Tuple items can be of any data type:

Example: String, int and boolean data types:

tuple1 = (“apple”, “banana”, “cherry”)
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)

Learn More About tuples functions in python in InsideAIML.

Comments

Popular posts from this blog

Tanh Activation Function

Sigmoid Activation Function And Its Uses.

Unleashing Creativity: The Latest Frontier of Animation AI