Intro to Python
Intro to Python
3 Loops 2
3.1 For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
4 Functions 3
5 Conclusion 3
1
1 Introduction
Variables store data in Python. They are created by assigning a value using the
= operator. Python supports several data types, including:
Example:
name = ”Alice” # String variable
age = 25 # Integer variable
height = 1.65 # Float variable
is_student = True # Boolean variable
3 Loops
Loops allow repetitive execution of code. Python supports for and while loops.
Example:
for i in range(5): # Prints 0 to 4
print(i)
Example:
2
count = 0
while count < 3:
print(”Count:”, count)
count += 1
4 Functions
Functions encapsulate reusable code. They are defined using the def keyword.
Example:
def greet(name):
return ”Hello,␣” + name + ”!”
message = greet(”Bob”)
print(message) # Outputs: Hello, Bob!
Functions can have multiple parameters and return values, enabling modular
programming.
5 Conclusion
These notes cover the basics of Python variables, loops, and functions. Practice
by writing small programs to reinforce these concepts. Additional resources are
available in Python’s official documentation (python.org).