Session Overview

  • Introduction to Python
  • Python Installation
  • Variables
  • Data Types
  • Input / Output
  • Operators
  • Conditional Statements

Introduction

Python is a high-level, interpreted, and easy-to-learn programming language. It is widely used for web development, automation, data science, artificial intelligence, desktop applications, and scripting.

Installation

Download Python from the official website:

Download Python

Variables

A variable is a named memory location used to store data. Variables help us store and reuse values in a program.

variable_name = value
Example 1 : Store Text
name = "Shree"
print(name)
Output
Shree
Example 2 : Store Number
age = 35
print(age)
Output
35
Example 3 : Multiple Variables
name = "Shree"
city = "Mumbai"
age = 35
            
print(name)
print(city)
print(age)
Output
Shree
Mumbai
35
Variable Naming Rules
  • Can contain letters, numbers and underscore (_).
  • Cannot start with a number.
  • Variable names are case sensitive.
  • Avoid Python keywords as variable names.
Valid Variable Names
name = "Shree"
student_name = "Vinayak"
age1 = 25
Invalid Variable Names
1name = "Shree"
student-name = "Vinayak"
class = "Python"

Data Types

Data Types define the type of value stored in a variable. Python automatically detects the data type based on the assigned value.

Common Data Types in Python
Data Type Description Example
int Whole Numbers 10
float Decimal Numbers 10.5
str Text/String Values "Python"
bool True or False True
Integer (int)
age = 25
print(age)
Output
25
Float (float)
salary = 25000.50
print(salary)
Output
25000.5
String (str)
course = "Python Django"
print(course)
Output
Python Django
Boolean (bool)
is_active = True
print(is_active)
Output
True
Finding Data Type using type()
name = "Shree"
age = 25
salary = 25000.50

print(type(name))
print(type(age))
print(type(salary))
Output
<class 'str'>
<class 'int'>
<class 'float'>

Input / Output

Displaying Output using print()
print("Welcome to Python")
Output
Welcome to Python
Accepting Input using input()
name = input("Enter Your Name : ")
print(name)
Output
Enter Your Name : Shree
Shree
Input and Output Together
city = input("Enter City : ")
print("City :", city)
Output
Enter City : Mumbai
City : Mumbai

Operators

Operators are special symbols used to perform operations on variables and values. Most operators in Python are similar to those used in C, C++, Java, C# and JavaScript.

Arithmetic Operators
Operator Description Example
+ Addition 10 + 5
- Subtraction 10 - 5
* Multiplication 10 * 5
/ Division 10 / 5
% Modulus 10 % 3
num1 = 10
num2 = 5

print(num1 + num2)
print(num1 - num2)
print(num1 * num2)
print(num1 / num2)
Output
15
5
50
2.0
Comparison Operators

Comparison operators are used to compare two values and return either True or False.

age = 18

print(age >= 18)
print(age < 18)
Output
True
False
Logical Operators

Logical operators are used to combine multiple conditions.

age = 25
citizen = True

print(age >= 18 and citizen)
Output
True

Conditional Statements

Conditional statements are used to execute different blocks of code based on a condition. They help programs make decisions.

if Statement

The if statement executes a block of code only when the condition is True.

age = 20
            
            if age >= 18:
                print("Eligible for Voting")
Output
Eligible for Voting
if else Statement

The else block executes when the condition is False.

age = 15
            
            if age >= 18:
                print("Eligible for Voting")
            else:
                print("Not Eligible for Voting")
Output
Not Eligible for Voting
if elif else Statement

The elif statement allows us to check multiple conditions.

marks = 75
            
            if marks >= 80:
                print("Grade A")
            elif marks >= 60:
                print("Grade B")
            elif marks >= 35:
                print("Grade C")
            else:
                print("Fail")
Output
Grade B
Nested if Statement

An if statement can be placed inside another if statement.

age = 25
            citizen = True
            
            if age >= 18:
                if citizen:
                    print("Eligible to Vote")
Output
Eligible to Vote

Quick Revision

Variables
  • Store Data
  • Reusable
  • Named Memory Location

name = "Shree"
Data Types
  • int → 25
  • float → 25.5
  • str → "Python"
  • bool → True
Input / Output
  • input()
  • print()
  • User Interaction
Operators
  • Arithmetic
  • Comparison
  • Logical
Conditions
  • if
  • if else
  • if elif else
  1. Create a program to display your Name, City and Age using variables.
  2. Accept student name as input and display it on screen.
  3. Accept two numbers and display their Addition.
  4. Accept marks and display "Pass" if marks are greater than or equal to 35, otherwise display "Fail".
  5. Accept age and display whether the person is eligible for voting or not.