Lists In Python

 

List is collection data type in python which used to store multiple values. List is like an array is used to collect multiple values. In the list any data can be saved and changed. For example: If you want to store city names in variables here list is used to store city values. List support different operations such as adding, removing, changing, popping and slicing values in lists.



cities = ["New York", "Tokyo", "London"]
print(cities)

# print list values with for loop
for city in cities:
    print(city)   
numbers = [1,2,3,4,5,6,7,8,9,10]
for num in numbers:
    print(num)
    
# length of list
print(len(numbers))

# retrieving values with index values
print(cities[0])


print(cities[1]) print(cities[2]) # Finding EVEN and ODD in list numbers = [1,2,3,4,5,6,7,8,9,10] for num in numbers: if num%2 == 0: print(str(num)+": EVEN") else: print(str(num)+": ODD") # sum all values in list numbers = [1,2,3,4,5,6] print(sum(numbers))
Github: https://github.com/asadraza825/python/blob/master/list.ipynb 
Tags: Python, Python Programming, Python Lists, Arrays
Next Post Previous Post
1 Comments
Add Comment
comment url