🖨️ Print Basics - Talking to Python
Learn how to use print() to display messages!
📖 What is Print?
The print() function is like Python's voice! It shows messages on your screen. You can print
text, numbers, or almost anything!
Printing Text
To print text (words), put your message inside quotation marks " " or ' '
Multiple Print Statements
Each print() creates a new line!
🎯 Quick Quiz
Question: What do you need to put around text when using print()?
💻 Try It Yourself!
Write a print statement that says "I am learning Python!"
🔢 Print Numbers - Math with Python
Learn how to print numbers and do calculations!
📖 Printing Numbers
You can print numbers WITHOUT quotation marks! Python knows they're numbers.
Math Operations 🧮
Python can do math! You can calculate and print the result:
Mixing Text and Numbers
You can use commas to print both text and numbers:
🎯 Quick Quiz
Question: What does print(4 + 6) show on the screen?
💻 Try It Yourself!
Print the result of 7 multiplied by 8 (use the * symbol)
📦 Creating Variables - Data Containers
Learn how to store information in variables!
📖 What are Variables?
Variables are like labeled boxes where you can store information. You can use that information later!
Creating a Variable
Use the equals sign = to create a variable:
No Declaration Needed! 🎉
In Python, you DON'T need to say "this is a variable" first. Just assign a value and boom - it's created!
Variables Can Change
You can change what's stored in a variable anytime:
🎯 Quick Quiz
Question: What symbol do we use to create a variable?
💻 Try It Yourself!
Create a variable called robot_name and set it to "ROBie"
✏️ Naming Variables - The Rules
Learn the rules for naming your variables!
📖 Variable Naming Rules
Python has important rules for naming variables. Follow them or your code won't work!
✅ The Rules (you MUST follow these!)
- ✅ Start with a letter (a-z, A-Z) or underscore (_)
- ✅ After the first character, you can use letters, numbers, or underscores
- ✅ Variable names are case-sensitive:
ageandAgeare different! - ❌ Cannot start with a number
- ❌ Cannot use spaces
- ❌ Cannot use special characters like !, @, #, $, %
Good Variable Names ✅
Bad Variable Names ❌
Best Practices 🌟
Make your variable names descriptive! Others (and future you) will thank you.
🎯 Quick Quiz
Question: Which variable name is CORRECT?
💻 Try It Yourself!
Create a variable with a good name for a student's grade. Make it descriptive!
🎯 Multiple Variables - Many at Once
Learn shortcuts to create many variables quickly!
📖 Assign Multiple Values
Python lets you create multiple variables in ONE line! This is super useful.
Three Variables, Three Values
You can assign three (or more) values to three variables at once:
One Value to Multiple Variables
Give the SAME value to multiple variables:
Mix Different Types
You can assign different types of data all at once:
🎯 Quick Quiz
Question: What does this code do? a, b, c = 5, 10, 15
💻 Try It Yourself!
Create three variables (red, green, blue) and assign them the values 255, 128, 0 in one line
📊 Output Variables - Printing Data
Learn different ways to print variables!
📖 Printing Variables
There are many cool ways to print variables and combine them with text!
Simple Variable Print
Just put the variable name inside print():
Print Multiple Variables
Use commas to print multiple variables. Python adds spaces automatically!
Mix Text and Variables
Combine your own text with variables:
The + Operator for Strings
You can use + to join strings (text) together:
⚠️ Warning: Numbers and Strings
You CANNOT use + to mix numbers and text directly. Python will get confused!
🎯 Quick Quiz
Question: What's the correct way to print a variable called score with text?
💻 Try It Yourself!
Create two variables: favorite_game and hours_played, then print them together with
text!
🌍 Global Variables - Everywhere Access
Learn about variables that work everywhere in your code!
📖 What are Global Variables?
Global variables are created OUTSIDE of functions. They can be used anywhere in your code!
Local vs Global 🎯
Variables created inside functions are LOCAL - they only work inside that function!
The global Keyword 🔑
If you want to CHANGE a global variable inside a function, use the global keyword:
🎯 Quick Quiz
Question: Where can you use a global variable?
💻 Try It Yourself!
Create a global variable called player_name and assign it your name!
🎓 Variable Practice - Test Your Skills
Put everything together with practice exercises!
📖 Let's Practice!
Now it's time to use everything you've learned! Complete these challenges.
Challenge 1: Create Variables
Can you create these variables?
- A variable for your name
- A variable for your age
- A variable for your favorite number
Challenge 2: Variable Math
Create two number variables, then print their sum!
Challenge 3: Update Variables
Variables can change! Update them and print:
🎯 Quick Quiz
Question: What happens when you run: x = 5, then x = x + 3?
💻 Final Challenge!
Create a mini program: Make variables for your name, age, and favorite hobby. Then print a sentence using all three!
🎨 Data Types - Different Kinds of Data
Learn about the different types of data Python uses!
📖 What are Data Types?
Data comes in different types! Just like how you have toys, books, and clothes - Python has different types of data.
Common Data Types 🎯
1. String (str) - Text/words
2. Integer (int) - Whole numbers
3. Float - Decimal numbers
4. Boolean (bool) - True or False
Checking Data Types 🔍
Use the type() function to see what type a variable is:
Why Types Matter ⚡
Different types work differently! You can add numbers, but adding a number to text causes errors:
🎯 Quick Quiz
Question: What data type is the number 3.14?
💻 Try It Yourself!
Create four variables, one of each type (str, int, float, bool), and use type() to check them!