This lecture you will learn python Lists in Python!
Lists in Python
names = ['perry','rita','john','kris','alice',]
print(names)
print(names[0]) // as we calling index item from list
print(names[-1]) // for negative index item
print(names[2:]) // index print from 2 item
print(names[2:4]) // index print range of 2 to 4
print(names[:]) // prints complete list
names = ['perry','rita','john','kris','alice',]
print(names[2:])
print(names)
also we can correct the list items on fly
names = ['perry','rita','john','kris','alice',]
names[0] = 'per'
print(names)
output:
['per', 'rita', 'john', 'kris', 'alice']
Exercise task for beginners:
Write a program to find the largest number in a list of given
numbers = “3, 5, 11, 2, 4, 10”
numbers = [3, 5, 11, 2, 4, 10]
max = numbers[0]
for number in numbers:
if number > max:
max = number
print(max)
output:
11