Collection is a group of elements stored with a single Name. Python has following collections
- Contains all types of values enclosed with the [ ] brackets
- Each value is called as Element or Item which will be identified based its position called Index.
- Index starts with 0.
Example List Creation
# List creation empList = [ 2001, 'Shivani',2005, 'Sanjay', 2007, 'Babu'] print ("employee Details : \n", empList) #specific element from List - Indexing print("2nd Position : ", empList) #printing Range of element - Slicing print("1st to 4th element : ", empList[0:4]) #printing from 2nd element to last element print("2nd to last element : ", empList[1:]) #printing the list two times - Repeation print(empList*2)
- Indexing – Retrieving the specific Element from the List.
- Slicing – Retrieving group of element from the List.
- Repeation – Printing the list to specified no. of times.
Win Corporate Training