
Python List are very similar to Array. List can store different datatype elements. A list contains things separated by commas and capsulate inside square brackets ([ ])
. List is a data type of collection of data which is ordered and changeable. List also allows duplicate members.
Features of Python Lists
- Ordered Lists
- Can change values after declaring elements
- Allow duplicate members
- Uses Brackets [ ]
- Can store different datatypes
Declaring List in Python
list1 = ['Study', 123, 1.25, 'Gyaan', 456]
list2 = ['Huzaif', 789]
print(list1)
print(list2)
Note – The plus (+) sign is the concatenation operator and the asterisk (*) is the repetition Operator. For example −
list1 = ['Study', 123, 1.25, 'Gyaan', 456] list2 = ['Huzaif', 789] print(list1) print(list1[0]) print(list1[0:3]) print(list1[2:]) print(list2*2) print(list1+list2)
It will produce output like this
>>> print(list1) ['Study', 123, 1.25, 'Gyaan', 456] >>> print(list1[0]) Study >>> print(list1[0:3]) ['Study', 123, 1.25] >>> print(list1[2:]) [1.25, 'Gyaan', 456] >>> print(list2*2) ['Huzaif', 789, 'Huzaif', 789] >>> print(list1+list2) ['Study', 123, 1.25, 'Gyaan', 456, 'Huzaif', 789]
Whats Next – Python Tuple