Python Logical Operators:
Logical operators are used to combine conditional statements. Python has three logical operators:
and- Returns True if both statements are true
or- Returns True if one of the statements is true
not - Reverses the result, returns False if the result is true
age = 25
has_ticket = True
has_coupon = False
# Example 1:
if age >= 18 and has_ticket:
print("Allowed entry.")
# Example 2:
if has_ticket or has_coupon:
print("Valid for entry or discount.")
# Example 3:
if not has_coupon:
print("No coupon provided.")
Relational operators or Comparison operators:
Comparison operators are used to compare two values:
user_age = 20
voting_age = 18
if user_age >= voting_age:
print("You are eligible to vote!")
else:
print("You are too young to vote.")
print(10 == 20)
print(10 != 20)
What is Runtime?
Runtime is the period when a Python program is executing, and the computer is performing the instructions written in the code.
Python Functions
- Python functions are reusable blocks of code used to perform a specific task.
- They help organize programs into smaller sections and execute the same logic whenever needed by calling the function.
def fun():
print("Welcome to Python")
fun()
Function Arguments
Arguments are values passed to a function when it is called. They allow functions to receive input data and perform operations using those values.
def evenOdd(x):
if (x % 2 == 0):
return "Even"
else:
return "Odd"
print(evenOdd(16))
print(evenOdd(7))
Method Overloading
- Method overloading is a feature of object-oriented programming where a class can have multiple methods with the same name but different parameters.
- To overload method, we must change the number of parameters or the type of parameters, or both.
Error in python
- SyntaxError: Missing colons :, unclosed parenthesis (), or quotes "".
- IndentationError: Incorrect spacing or mixing tabs and spaces.
- TypeError: Combining incompatible data types, like adding a string to an integer.

Top comments (0)