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 – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho
☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw
Blog: http://digital.academy.free.fr/blog/
Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners
Shopping and Discounts: http://digital.academy.free.fr/store/
#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/
✧ https://twitter.com/DigitalAcademyy
✧ https://www.facebook.com/digitalacademyfr
✧ https://www.instagram.com/digital_academy_fr/
✧ https://www.youtube.com/c/DigitalAcademyOnline
♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧ https://www.patreon.com/digital_academy
✧ https://www.buymeacoffee.com/digital_academy
***