Python_2
Python_2
Today you'll dive into Python’s fundamental building blocks by learning about variables, data
types, and basic operations. Follow this detailed plan and complete the exercises to solidify your
understanding.
What to Know:
• Statements:
Each line of code is a statement. Unlike some languages, you don’t need to end statements
with a semicolon.
• Comments:
Use the hash symbol (#) for comments. Anything following # on that line is ignored by
Python.
Quick Example:
# This is a comment
A. Variables
• Definition:
Variables store data values. In Python, you don’t need to declare the type; it’s determined
automatically.
• Assignment:
Use the equals sign (=) to assign values to variables.
B. Data Types
age = 30
pi = 3.14159
name = "Alice"
Practice:
• Open your code editor (or interactive Python shell) and type the following:
# Integer
number = 10
# Float
fraction = 3.14
# String
# Boolean
status = False
Operations to Explore:
• Addition: +
• Subtraction: -
• Multiplication: *
• Division: /
• Exponentiation: **
• Modulus (Remainder): %
Example:
a = 15
b=4
print("Addition:", a + b) # 19
print("Subtraction:", a - b) # 11
print("Multiplication:", a * b) # 60
print("Division:", a / b) # 3.75
Practice:
python
print(7 + 3)
x = 10
y = 5.5
print(message)