Chap2 Programming Python
Chap2 Programming Python
CO2039
02 DATA STRUCTURES
04 CONCLUSION
2
VARIABLES &
01 DATA TYPES
3
Python Syntax Overview
# Python (No semicolons, indentation-based)
print("Hello, Python!")
5
02 DATA STRUCTURES
6
Python Built-in Data Structures
⇒ No duplicates, unordered
● Dictionaries (Key-Value Pairs)
student = {"name": "Alice", "age": 20}
print(student["name"]) # Output: Alice
8
Type conversions
x = 10
y = str(x) # Convert int to string
print(y) # Output: "10"
Common conversions:
● int("100") → Converts string to integer
● float("3.14") → Converts string to float
● str(50) → Converts integer to string
9
CONDITIONALS,
03 LOOPS &
EXCEPTIONS
10
Conditional Statements
age = 18
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")
11
Loops
● for Loop (Iterate over a sequence)
for i in range(5):
print(i) # Output: 0 1 2 3 4
15
03 CONCLUSION
16
Conclusion
17
Thank you for your
attention!
https://www.cse.hcmut.edu.vn