Back to Blog
Jan 22, 20232 min read

Tuples in Python

Python
Tuples in Python

A tuple in Python is an ordered collection of items, similar to a list. However, unlike lists, tuples are immutable, which means that the items inside a tuple cannot be modified after it is created. Tuples are enclosed in parentheses () and the items inside a tuple are separated by commas.

https://youtube.com/@codewithmuh

Here’s an example of a tuple in Python:

coordinates = (4, 5)

In the example above, coordinates is a tuple containing two integer items.

Tuples are commonly used to store related data, such as a person’s name and age:

person = ("John", 30)

You can access the items in a tuple using indexing, just like a list:

print(person[0]) # prints "John"

You can also use the built-in function len() to find the number of items in a tuple and the built-in function tuple() to convert a list to a tuple.

Tuples are more memory efficient than lists and are generally used when the data inside it is not intended to be modified. They are also used as a key in a dictionary, since dictionary keys need to be immutable.

In summary, tuples in python are similar to lists but they are immutable and they are used to store a collection of related data, they are also more memory efficient and are commonly used as keys in a dictionary.

If you Want to Learn Python, You can watch my ultimate Python Course on My Youtube Channel.

You can join there as well to share your Queries and suggestions. Facebook Facebook Group: https://web.facebook.com/groups/890525732087988/?mibextid=HsNCOg

Thanks For Reading.

You can Also Follow Me on My Social Media Platforms:

  1. Facebook
  2. Youtube
  3. Twitter & Instagram
  4. GitHub & Replit
  5. Upwork

💬 Got questions? Ask me anything!