Chapter 1: Variables, Data Types, and Strings
1. Introduction
Python is a simple, powerful programming language used in many fields, including civil engineering. In this
chapter, students will learn about variables, different types of data, and string manipulation.
2. Variables
A variable stores data in memory.
Example:
name = 'Houria'
age = 30
Correction: The variable 'name' stores a string and 'age' stores a number.
3. Data Types
Python has several basic data types:
• int → integers (5, 10, -3)
• float → decimals (3.14, 2.0)
• str → strings ('Hello')
• bool → Boolean values (True or False)
Example:
a = 5
b = 3.5
c = 'Python'
d = True
print(type(a), type(b), type(c), type(d))
4. String Operations
Strings are sequences of characters. You can use several built-in functions:
text = 'Python Programming'
print([Link]())
print([Link]())
print([Link]())
print([Link]('Python', 'Civil'))
Correction:
PYTHON PROGRAMMING
python programming
['Python', 'Programming']
Civil Programming
Teacher Notes
• Remind students that variable names cannot start with numbers or contain spaces.
• Explain that Python automatically detects the type of data.
• Use print statements often to check what a variable contains.
Exercises
Exercise 1: Create a variable for your name, your age, and your favorite subject. Print them in one line.
Solution:
name = 'Houria'
age = 30
subject = 'Python'
print('My name is', name, ', I am', age, 'years old and I love', subject)
Exercise 2: Use string functions to convert a sentence into lowercase, uppercase, and split it.
Solution:
sentence = 'Learning Python is Fun'
print([Link]())
print([Link]())
print([Link]())
Summary
• A variable is used to store data in memory.
• Each variable has a data type (int, float, str, bool).
• The print() function displays results.
• Strings can be modified using built-in functions like upper(), lower(), replace(), and split().
Mini Quiz
• 1. Which of the following is a valid variable name? (c) my_name
• 2. What is the output of type(3.5)? → float
• 3. What does [Link]() do? → Converts all letters to uppercase.