Python Lesson 1
Python Lesson 1
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
What is Python?
Python is a:
1
Python Programming Lecture 1
Explanation:
• print() is a function
Creating Variables
age = 21
height = 1.75
name = " Ahmed "
Important Rule
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 ’
• Letters
• Numbers
• Symbols
String Operations
Boolean (bool)
Booleans represent logical values.
is_student = True
has_id = False
• Conditions
• Decision making
3
Python Programming Lecture 1
height = 1.75
height_str = str ( height )
Warning
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 : " ) )
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.
Lecture Summary
• Python is simple and powerful
• Practice is essential