Learn how to use print() to display messages!
The print() function is like Python's voice! It shows messages on your screen. You can print
text, numbers, or almost anything!
To print text (words), put your message inside quotation marks " " or ' '
Each print() creates a new line!
Question: What do you need to put around text when using print()?
Write a print statement that says "I am learning Python!"
Learn how to print numbers and do calculations!
You can print numbers WITHOUT quotation marks! Python knows they're numbers.
Python can do math! You can calculate and print the result:
You can use commas to print both text and numbers:
Question: What does print(4 + 6) show on the screen?
Print the result of 7 multiplied by 8 (use the * symbol)
Learn how to store information in variables!
Variables are like labeled boxes where you can store information. You can use that information later!
Use the equals sign = to create a variable:
In Python, you DON'T need to say "this is a variable" first. Just assign a value and boom - it's created!
You can change what's stored in a variable anytime:
Question: What symbol do we use to create a variable?
Create a variable called robot_name and set it to "ROBie"
Learn the rules for naming your variables!
Python has important rules for naming variables. Follow them or your code won't work!
age and Age are different!Make your variable names descriptive! Others (and future you) will thank you.
Question: Which variable name is CORRECT?
Create a variable with a good name for a student's grade. Make it descriptive!
Learn shortcuts to create many variables quickly!
Python lets you create multiple variables in ONE line! This is super useful.
You can assign three (or more) values to three variables at once:
Give the SAME value to multiple variables:
You can assign different types of data all at once:
Question: What does this code do? a, b, c = 5, 10, 15
Create three variables (red, green, blue) and assign them the values 255, 128, 0 in one line
Learn different ways to print variables!
There are many cool ways to print variables and combine them with text!
Just put the variable name inside print():
Use commas to print multiple variables. Python adds spaces automatically!
Combine your own text with variables:
You can use + to join strings (text) together:
You CANNOT use + to mix numbers and text directly. Python will get confused!
Question: What's the correct way to print a variable called score with text?
Create two variables: favorite_game and hours_played, then print them together with
text!
Learn about variables that work everywhere in your code!
Global variables are created OUTSIDE of functions. They can be used anywhere in your code!
Variables created inside functions are LOCAL - they only work inside that function!
If you want to CHANGE a global variable inside a function, use the global keyword:
Question: Where can you use a global variable?
Create a global variable called player_name and assign it your name!
Put everything together with practice exercises!
Now it's time to use everything you've learned! Complete these challenges.
Can you create these variables?
Create two number variables, then print their sum!
Variables can change! Update them and print:
Question: What happens when you run: x = 5, then x = x + 3?
Create a mini program: Make variables for your name, age, and favorite hobby. Then print a sentence using all three!
Learn about the different types of data Python uses!
Data comes in different types! Just like how you have toys, books, and clothes - Python has different types of data.
1. String (str) - Text/words
2. Integer (int) - Whole numbers
3. Float - Decimal numbers
4. Boolean (bool) - True or False
Use the type() function to see what type a variable is:
Different types work differently! You can add numbers, but adding a number to text causes errors:
Question: What data type is the number 3.14?
Create four variables, one of each type (str, int, float, bool), and use type() to check them!