List operations: The item at a certain index in a list can be reassigned .
For example:
nums=[7,7,7,7,]
nums[2]=5
print(nums)
Now this will be added at index number [2]/
List can be added and multiplied in same way as strings.
Ex:
nums[1,2,3]
print(nums+[4,5,6])
print(nums*3)
We can also check whether a word is available in list with the help of in operator and if present evaluates to true and if not present evaluates to false
print(“egg” in words)
Similarly we can use not operator also if it is present in list or not.
List functions: Another way of altering data is using functions
append: nums[1,2,3]
nums.append(4)
len- It is used to check length of list.
len(nums)
Insert :It allows us to insert value anywhere in list
words.insert(index,”is”)
Index- finds occurrence of list item and return its index
print(letters.index(‘r’)
While loop:
If statement is run once the condition evaluates true and never if evaluates false.
Syntax:
while<condition>:
i=1
while i<5:
Print(i)
i=i+1
For loop:The for loop is used to write all the condition and value in single line and make the loop execute
Syntax:for <variable> in expression:
Comments