Python
Programming
B Y P R OF. U JA LA Z A I NAB
What is the basic concept of
programming?
Programming is the process of giving instructions to a
computer to perform specific tasks. These instructions are
written using programming languages like Python, C, or
Java. The main goal of programming is to solve problems by
designing logical steps that a computer can follow. It
involves writing, testing, and maintaining code to create
software, apps, websites, and much more.
Basics of programming:
Computer programming involves the following basic steps to write
a program.
1. Write Code: Create a set of instructions in a programming
language.
2. Compile/Interpret: Translate the code into a form that the
computer can understand.
3. Execute: Run the code to perform the task.
4. Output: Display the results or perform actions based on the
code
Example:
Step#1: Write Code
num1 = 5
num2 = 3
sum = num1 + num2
print("The sum is:", sum)
Example:
Step#2: Compile/Interpret
• Python interpreter reads each line of code and translates it
into machine instructions.
• The computer now understands: “Take 5, add 3, and save
the result.”
Example:
Step#3 Execute:
• The code runs.
• The computer performs the operation: 5 + 3 = 8.
Step#4 Output:
The sum is: 8
• This result is displayed on the screen for the user.
Graphical Representation:
[Write Code] → [Interpret] → [Execute] → [Output]
↓ ↓ ↓
num1=5, num2=3 Perform 5+3 Show “The sum is: 8”
Introduction to Python:
Python is a high-level, easy-to-learn programming language created by Guido
van Rossum and released in 1991. It is known for its simple syntax, which is similar
to everyday English, making it perfect for beginners as well as professionals.
Python is used for:
• Web Development
• Data Science & AI
• Automation & Scripting
• Software & App Development
Because of its readability and wide range of libraries, Python has become one
of the most popular programming languages in the world.
Setting Up Python Development
Environment:
To start writing and running Python programs,
we need to set up our computer properly.
This is called the development environment.
What do we need?
• Python Software – Download it from:
🌐 www.python.org
• IDE (Integrated Development Environment)
– This is a tool that helps you write, test, and
fix your code easily.
Installing Python & Running It Easily
Popular IDEs for Python:
• IDLE (comes with Python)
• Thonny (great for beginners)
• VS Code (used by professionals)
Here’s a list of popular mobile IDEs and code editors
you can install on your Android or iOS device:
• Cross-Platform (Android & iOS):
Dcoder – Supports C, C++, Java, Python, HTML, CSS,
JavaScript & more
• Only on iOS:
Pythonista (for Python)
Swift Playgrounds (for Swift – made by Apple)
• Only on Android:
AIDE (for Android app development)
Basic Python Syntax and Structure:
• Python File Extension:
Python files end with .py
Example: Hello.py
• Print Statement:
Used to display output
print("Hello, World!")
• Indentation:
Spaces are used instead of brackets {}
if 5 > 3:
print("Yes") # Indented line
• Comments:
1. Use # for single-line comments
Example:
# This is a comment
2. You can also use triple quotes for multi-line text that looks like a
comment, but technically it's a multi-line string, not a real
comment:
Example:
''‘
This is a multi-line string.
It can be used like a comment.
Python will ignore it if it’s not assigned.
''‘
• Variable: • Input from User:
No need to declare data type. Take input using input()
Example: Example:
name = "Ujala" name = input("Enter your name: ")
age = 25
• Basic Data Types: • Functions:
Int, Float, str, Bool etc. Define using def
Example:
def greet():
print("Hi!")
Variable Naming Rules in Python
Variable names in Python must adhere to the following rules:
• The name must begin with a letter (a-z, A-Z) or an
underscore ( _ ).
• Subsequent characters can include letters, digits (0-9), or
underscores ( _ ).
• Variable names are case-sensitive, meaning age and Age
are considered two different variables.
• Python's reserved keywords, such as for, while, if, etc.,
cannot be used as variable names.
Creating Different Types of Data Variables in
Python
• Integer (int)
Stores whole numbers.
Example:
age = 17
• Float (float)
Stores decimal numbers.
Example:
price = 19.99
• String (str)
Stores text or characters.
Example:
name = "Ali”
• Boolean (bool)
Stores either True or False.
Example:
is_student = True
NOTE: No need to declare type — Python figures it out
automatically!