Python Tuples

What is tuple in python?

A tuple is list of python. Tuple uses parentheses (). Tuple does not use square brackets [].
Tuple items are ordered. Tuple items cannot be change. Tuple allows duplicate values.

In tuple you can write any type of value like int, float, string, boolean, etc.

Syntax

tuple_name = (item-1,item-2,item-3,.......)

example:
my_tuple = (100,200,True,'Hi',500,300)

See Output

How to get length of Tuple?

The len() function used to get length of tuple in python program.
The len() is a predefined function in python.

See Output

How to get data type of tuple?

The type() is function used to get data type of tuple.

See Output

How to write single element in tuple?

If you want to create a tuple with single element then write comma(,) after element in tuple.

See Output

What is difference between List and Tuple?

The square brackets [] are used to write elements in the list but parentheses () are used to write elements in the tuple.

The list is mutable but the tuple is not mutable. It means you can change or modify the list item but you cannot change or modify the tuple item.


About Us

Comsysapp.com is an educational website. Students and software developers can learn programming language tutorials. Comsysapp is very useful for beginners and professional developers. Comsysapp provides tutorial in easy language. Comsysapp.com has focus on simplicity.

Services

Comsysapp.com provides free tutorials like c, html, css, etc. All tutorials are free for beginner and professionals.


Terms of Use

comsysapp.com is not responsible for any mistake. We are not responsible if information made available on our website is incomplete or invalid. But comsysapp.com always try for zero-zero mistake.

Privacy policy

comsysapp.com does not collect any data from users. We use Google AdSense advertising on our website. We never ask personal or private information.


Sitemap

sitemap

copyright © 2023