What is Tuple in Python ?
A tuple refers to a collection of objects in python which are ordered and ca n’t be modified. The python things then may be strings, lists, tuples, integers etc.
Therefore, they preserve a precise order. Also, the tuple is inflexible. As a result, tuples don't revise after the original tasking of elements.
Illustration
tuple1 = (‘ red’, ‘orange’,‘ blue’)
print( tuple1)
Output ‘ red’, ‘orange’,‘ blue’
When should we go for tuple data structure in python?
Still, also we should come for tuple data structure, If we're going to define a data which isn't going to modify over the period. For example, weekdays, timetable months, years etc. Let us have an illustration for better agreement.
Data types are applied to store varied details. Thus, all programming languages have unidentified data types. Python is no exception. The other data types in Python are Set, List, and Dictionary. Still, we shall restrict the discussion to the tuple (). Tuple in Python refers to a collection that's ordered. A tuple collects the same or different collections of objects. Therefore, the round brackets () different each element in a tuple.
List
The Python List is one of the most applicable sequences in authentic- time. List methodology in Python is the most adaptable data- type accessible in Python that can exist written as a collection of comma- separated values or details between square brackets. The details in a list need not necessarily be homogeneous, i.e. of the identical type.
Fundamentals of a list are listed according to a particular sequence and the indexing is served with 0 being the starting index. Indeed element of a list has its special place in the list, which allows duplication of the rudiments in the list, with each element possessing its own different place and credibility. Lists are a applied tool for putting up a sequence of data.
Conclusion
In this article ,we discuss about List and Tuple in Python. You can also check our another article for difference between list and tuple in python.
Comments