Python Basics Flashcards
Variable Names
What do computers use variables for?
To remember informaion
Variable Names
To create a variable, we start by typing it name. Variable names need to be single words and therefore have no spaces.
city
Variable Names
If we want a variable name with multiple words, we use snake case. Snake case means using _ to connect the additional words.
home_city
Variable Names
What’s wrong with this variable name?
high score
There is a space between the words.
Variable Names
To help us understand what’s inside a variable we pick descriptive names.
home_city_province
Variable Names
What do we use snake case for?
To create variable names with multiple words.
Updating Variables
Why do we give variables descriptive names like city or population instead of c or p?
To help us understand what’s inside them.
Expressions
We can add string values together with a + sign
“Followers:” + “55”
Expressions
We call adding string values and expression as the output creates a single value.
In this example, only oh string is displayed output when we add “55” inside print().
print(“Followers:” + “55”)
Followers:55
Expressions
When expressions contain variables, they use the values in the variables, which we can see when adding “Followers:” to followers.
followers = “55”
print (“Followers:”+followers)
Expressions
Since expressions become values, we can store them in variables the same way as values.
See the example her where we’ll code label to display the expression.
label = “Posts:” + “13”
print(label)
Posts:13
Expressions
What’s the value of label?
label = “Name:” + “Joe”
“Name:Joe”
Expressions
What does the code display in the console?
user = “snoopdogg”
print(“Username:” + user)
Username:snoopdogg
Expressions
Add temperature variable to the expression.
temperature = “14”
print(temperature + “ degrees”
14 degrees
Expressions
Display Posts:55 in the console
Print (“Posts:” + “55”)
Posts:55