Day 2 of Python (Operators and Conditional Statements)
Source: Dev.to
Operators
Operators are used to perform operations on values and variables.
Types of operators

Arithmetic operators
Used to perform basic mathematical operations like addition, subtraction, multiplication, etc.
Comparison operators
Used to compare values; they return True or False according to the given condition.
Logical operators
Used to perform logical AND, OR, and NOT operations. They combine conditional statements.
Assignment operators
Used to assign values to variables (the value on the right side of the expression is assigned to the left‑hand operand).
Formatted string (f‑string)
Allows inserting variables or values directly inside a string.
name = input("What is your name ")
print("Your name is ", name)
age = int(input("What is your age "))
print("Your age is ", age)
gender = input("What is your gender ")
print("Your gender is ", gender)
print(f"Your name is {name} age {age} gender {gender}")
Sample output
What is your name Vidya
Your name is Vidya
What is your age 20
Your age is 20
What is your gender Female
Your gender is Female
Your name is Vidya age 20 gender Female
By default, input from the user is stored as a string.
Typecasting
Converting from one data type to another.
- Implicit typecasting – automatic conversion performed by Python.
- Explicit typecasting – manual conversion using functions like
int(),float(),str(), etc.
Strings
A sequence of characters used to represent data. Strings can be defined with single quotes (' '), double quotes (" "), or triple quotes (""" """) for multi‑line text.
Indexing
Accessing individual elements using their position (index) in a sequence.
Negative indexing
Accessing elements from the end of a sequence using negative numbers.
Slicing
Extracting a part of a sequence (e.g., a string or list) by specifying start and end indices.
Conditional Statements
Conditional statements allow a program to make decisions based on given conditions.
Types of conditional statements
ifstatement – Executes code only if the condition is true.if‑elsestatement – Provides an alternative block of code when the condition is false.elifstatement – Handles multiple mutually exclusive conditions.