Python Notes
Python Notes
Python Notes
Ques1. Explain the relational operator used for checking the condition?
Relational operators compare the values. It either returns True or False according to the condition.
The if statement in python is used to test a condition. If condition is true, statement of if block is
executed otherwise it is skipped. Syntax of python if statement:
if(condition):
statements
When the condition is true, then code associated with if statement will execute, otherwise code
associated with else statement will execute.
Example:
a=10
b=20
if a>b:
print(“a is greater”)
else:
print(“b is greater”)
To check for multiple conditions elif Statement is used. This statement is like executing a if
statement inside a else statement.
Syntax:
If statement:
statements
elif statement:
statements
else:
statements
The input () is a built-in function in python that retrieves the input from the user.
Example:
Accessing lists:
The values stored in a list can be accessed using the slice operator ([ ]) with indexes.
The first item in the list has the index zero (0).
Example :
list2 = [1, 2, 3, 4, 5, 6, 7 ];
Example :
thislist.append("orange")
print(thislist)
or
Insert Items :
Example :
thislist.insert(1, "orange")
print(thislist)
Example :
thislist.remove("banana")
print(thislist)
or
Example
thislist = ["apple", "banana", "cherry"]
thislist.pop(1)
print(thislist)
or
thislist.pop()
print(thislist)