top of page

Python Tutorial

Public·1 member

Python List - CodersArts

Basic of List



grocery = ["Bread","Butter","Milk","Vim Bar","Handwash"]
print(grocery)

numbers = [14,0,7,15,10]
print(numbers[2])

# slicing of list when we do this then this slicing returns new list not update the original list
print(numbers[0:5])
print(numbers[:5])
print(numbers[:])
print(numbers[1:4])

# This method will change the original list
print(numbers.sort())
print(numbers.reverse())

# extended slice here you will get blank thats why we should always take 3 value -1 not less than -1
print(numbers[1:5:-3])

# it will reverse as i told u earlier that 3 value is -1 then it reverse the list so -3 then it reverse the list and in this case you will get
print(numbers[::-2])

12 Views
bottom of page