Python Programming Lecture 1
Python Programming: Lecture 1
Introduction, Variables, and Data Types
Introduction to Programming
Programming is the process of giving instructions to a computer to perform a task. A program
is a sequence of instructions written in a language that the computer understands.
Key Idea
A computer does exactly what you tell it to do — no more, no less.
What is Python?
Python is a:
• High-level language (easy for humans to read)
• Interpreted language (runs line by line)
• Dynamically typed language (no need to declare variable types)
Python is widely used because it focuses on readability and simplicity.
Why Learn Python?
• Beginner-friendly syntax
• Massive community and libraries
• Used in AI, Robotics, Web, Games, Automation
• Industry and research standard
Python Environment: Google Colab
Google Colab allows you to:
• Write Python code in your browser
• Run code without installing Python
• Share notebooks easily
Each Colab cell executes code from top to bottom.
1
Python Programming Lecture 1
Your First Python Program
print ( " Hello , World ! " )
Explanation:
• print() is a function
• Functions perform specific actions
• This function displays output
Variables and Memory
A variable is a name given to a memory location.
Creating Variables
age = 21
height = 1.75
name = " Ahmed "
Important Rule
Variables are created the moment you assign a value to them.
Rules for Variable Names
• Must start with a letter or underscore
• Cannot start with a number
• Cannot contain spaces
• Case-sensitive (Age ̸= age)
Data Types in Python
A data type tells Python:
• What kind of data is stored
• What operations are allowed
Integer (int)
Integers represent whole numbers.
x = 10
y = -3
z = 0
2
Python Programming Lecture 1
Common uses:
• Counting
• Indexing
• Discrete values
Float (float)
Floats represent decimal numbers.
pi = 3.14159
temperature = 36.6
speed = -2.5
Note
Division in Python usually produces a float.
String (str)
Strings represent text data.
name = " Ali "
message = ’ Python is fun ’
Strings can include:
• Letters
• Numbers
• Symbols
String Operations
first = " Hello "
second = " World "
print ( first + " " + second )
print ( len ( first ) )
Boolean (bool)
Booleans represent logical values.
is_student = True
has_id = False
Used mainly for:
• Conditions
• Decision making
3
Python Programming Lecture 1
Type Checking and Type Conversion
Checking Data Type
x = 10
print ( type ( x ) )
Type Conversion (Casting)
age = " 21 "
age_number = int ( age )
height = 1.75
height_str = str ( height )
Warning
Invalid type conversion will cause an error.
Basic Operations
Arithmetic Operations
Operation Example
Addition 5 + 3
Subtraction 5 - 3
Multiplication 5 * 3
Division 5 / 3
Power 5 ** 3
a = 10
b = 4
print ( a + b )
print ( a / b )
print ( a ** b )
User Input
name = input ( " Enter your name : " )
age = int ( input ( " Enter your age : " ) )
print ( " Hello " , name )
print ( " You are " , age , " years old " )
4
Python Programming Lecture 1
Practice Tasks
Task 1
Create variables for your name, age, and height. Print them.
Task 2
Ask the user for two numbers and print their sum and product.
Task 3
Store whether a user is a student using a boolean variable.
Challenge Task
Ask the user for a number and print its square and cube.
Common Beginner Mistakes
• Mixing strings and integers without conversion
• Forgetting quotation marks
• Using unclear variable names
Lecture Summary
• Python is simple and powerful
• Variables store data
• Data types define behavior
• Practice is essential
Next Lecture: Conditional Statements and Loops