def list python code example

Example 1: list in python

#list is data structure 
#used to store different types of data at same place
list = ['this is str', 12, 12.2, True]

Example 2: python list function

# empty list
print(list())

# vowel string
vowel_string = 'aeiou'
print(list(vowel_string))

# vowel tuple
vowel_tuple = ('a', 'e', 'i', 'o', 'u')
print(list(vowel_tuple))

# vowel list
vowel_list = ['a', 'e', 'i', 'o', 'u']
print(list(vowel_list))

Example 3: python list

# Create list
List = list()
List = []
List = [0, "any data type can be added to list", 25.12,
        ("Even tuples"), {"Dictionaries": "can also be added"},
       ["can", "be nested"]]
# Accessing items

List[1]		# 0
List[-1] 	# ["can", "be nested"]

# Operations
List.append(4)		# adds 4 to end
List.pop(n=-1)		# removes element from nth position
List.count(25.12)	# 1