Print Statements and If Conditions
Want to see results from your code? The print() function displays information on your screen. It's like telling Python to show you what's happening inside your program:
print("Hello World!")
print(3.14)
Making decisions is a key part of programming, and that's where if statements come in. They let your program check conditions and do different things based on whether those conditions are true or false:
if age >= 18: # condition
print("Hello,", name)
print("You are an adult.")
else: # otherwise
print("Hello,", name)
print("You are a minor.")
You can handle multiple conditions by adding elif (short for "else if") between your if and else statements. This creates a chain of checks that makes your program even smarter about how it responds to different situations.
Remember: Indentation matters in Python! The indented lines after an if statement are what runs when the condition is true, so be careful with your spacing.