Welcome to Python! 🐍
Python is a fun and easy programming language that you can use to make cool things!
print("Hello, Python Adventure!")
This line tells Python to show the message "Hello, Python Adventure!" on the screen.
Variables: Python's Memory Boxes 📦
Variables are like labeled boxes where Python stores information for later use.
age = 10
name = "Python Explorer"
print("Hi! I'm a", age, "year old", name)
Here, we created two variables: 'age' and 'name'. We can use these variables in our code!
Data Types: Different Kinds of Information 🔢
Python can work with different types of data. Let's explore some!
- Integers (whole numbers):
5, 10, -3
- Floats (decimal numbers):
3.14, -0.5, 2.0
- Strings (text):
"Hello", 'Python', "123"
- Booleans (True or False):
True, False
age = 10 # Integer
height = 1.5 # Float
name = "Alice" # String
is_student = True # Boolean
Conditionals: Making Decisions 🔀
Conditionals help Python make decisions based on certain conditions.
temperature = 25
if temperature > 30:
print("It's hot outside!")
elif temperature > 20:
print("It's a nice day!")
else:
print("It's a bit chilly.")
This code checks the temperature and prints different messages based on how warm it is.
Loops: Doing Things Over and Over 🔁
Loops help us repeat actions without writing the same code multiple times.
for i in range(5):
print("Python is awesome!")
count = 0
while count < 5:
print("Count is:", count)
count += 1
The first loop prints "Python is awesome!" 5 times. The second loop counts from 0 to 4.
Functions: Reusable Blocks of Code 🧩
Functions are like recipes that you can use over and over again in your code.
def greet(name):
return f"Hello, {name}!"
message = greet("Python Learner")
print(message)
This function takes a name and returns a greeting. We can use it with different names!