Python – Lists

Python Lists are very similar to Array. List can store different datatype elements. A list contains items separated by commas and enclosed within square brackets ([ ]). List is a collection which is ordered and changeable. Allows duplicate members.

Features of Python Lists

  1. Ordered Lists
  2. Can change vlaues after declaring elements
  3. Allow duplicate members
  4. Uses Brackets [ ]
  5. 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)
Filed under: Python

No comment yet, add your voice below!


Leave a Reply