Comparison operator
the operator used to compare the two values(<,>,<=,>=,==)
a = 10
b = 20
print(a == b) # False (10 is not equal to 20)
print(a != b) # True (10 is not equal to 20)
print(a > b) # False (10 is not greater than 20)
print(a < b) # True (10 is less than 20)
print(a >= 10) # True (10 is equal to 10)
print(b <= 20) # True (20 is equal to 20)
Terinary operator
The ternary operator is just a one-line shortcut for if...else.
num = 5
result = "Even" if num % 2 == 0 else "Odd"
print(result)
Logical operator
A logical operator in Python is used to combine or modify conditions (expressions that evaluate to True or False). They help in decision-making by controlling the flow of the program.
1.and → Returns True if both conditions are true.
2.or → Returns True if at least one condition is true.
3.not → Reverses the result (True becomes False, False becomes True).
x = 10
y = 20
# AND operator
print(x > 5 and y > 15) # True (both conditions are true)
# OR operator
print(x > 15 or y > 15) # True (second condition is true)
# NOT operator
print(not(x > 5)) # False (since x > 5 is True, not makes it False)
Run time & Compile time
run time refers to when a program is actively running.
compile time refers to the stage where python checks your code and convert into byte code.
Function overloading
same method name with different number of parameter
example:
add(int a, int b)
add(double a, double b)
Function
Set of instruction with name.
It is a block of code which runs when it is called.
Name must be start with a letter or underscore.
def greet(name):
return "Hello, " + name
print(greet("vishwa"))
output: Hello, vishwa
Top comments (0)