Tuples in Python: Definition, Syntax & Advantages (Tuples vs Lists) - Python Tutorial for Beginners

Publié le: 28 mars 2021
sur la chaîne: Digital Academy
657
18

🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ Tuples in Python: Definition, Syntax and Advantages (Tuples vs Lists)

Python provides another kind of Data Type in Python, called a tuple. Tuples in Python are a lot like Lists in Python: they are used to collect objects in order. Consequently, everything you have learned about Lists in Python is true, for tuples as well.

○ Tuples are ordered: Tuples maintains a left-to-right positional ordering ;
○ Accessed by index: Items in a tuple are accessed and sliced using an index ;
○ Tuples can contain any sort of object: numbers, strings, lists and other nested tuples ;
○ Tuples are immutable: you cannot add, delete or change items after the tuple is created.

A tuple in Python is an ordered collection of values, which is accessed by index and it can contain any sort of objects, like: numbers, strings, lists, or even other nested tuples.

Lists and Tuples can contain duplicate members! Except that tuples are immutable, which means you theoretically cannot: add, delete or change items inside the tuple once created.

Nonetheless, you can iterate through a tuple in Python, with a simple for loop as well.

---

○ Why use a Tuple instead of a List in Python?

Program execution is faster when manipulating a Tuple, than it is for the equivalent List.
Sometimes you do not want data to be modified. If the values in the collection are meant to remain constant for the life of the program, using a tuple instead of a list protects your data from accidental modification (add / remove).
There is another Python data type called a Dictionary, which requires as keys a value that is of an immutable type. A tuple can be used for this purpose, whereas a list cannot be.

---

Awesome, you know what a tuple can be used for! But, How to declare a tuple, pack and unpack some values in a tuple, or even access specific items?

Let's play this video, stick around and watch until the end of this video! 👍🏻

Digital Academy™ 🎓

***

☞ WATCH NEXT:
○ Data Types in Python -    • DATA TYPES in Python (Numbers, Strings, Li...  
○ Operators in Python -    • OPERATORS in Python (Arithmetic, Assignmen...  
○ IF Statements in Python -    • CONDITIONAL Statements in Python (IF, ELIF...  
○ FOR Loops in Python -    • FOR Loop in Python (Syntax, Break, Continu...  

📖 Blog: http://digital.academy.free.fr/blog

📖 [FULL Course] HOW TO Learn Python? Python Tutorial for Beginners:    • 🐍 Python 101: Learn Python Basics for Abso...  

📖 [PLAYLIST] Complete Python Development Course for Beginners: http://digital.academy.free.fr/playli...

🧑‍🎓 [COURSE] http://digital.academy.free.fr/courses

📘 [BOOK] Python for Absolute Beginners: https://amzn.to/3NvyOWV

🛒 Shopping and Discounts: http://digital.academy.free.fr/store

💌 Weekly Newsletter for Developers: https://www.getrevue.co/profile/digit...

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧   / digitalacademyy  
✧   / digitalacademyfr  
✧   / digital_academy_fr  
✧    / digitalacademyonline  

♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/store
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧   / digital_academy  
✧ https://www.buymeacoffee.com/digital_...

***


Sur cette page du site, vous pouvez voir la vidéo en ligne Tuples in Python: Definition, Syntax & Advantages (Tuples vs Lists) - Python Tutorial for Beginners durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Digital Academy 28 mars 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 657 fois et il a aimé 18 téléspectateurs. Bon visionnage!