Python Variables Basics
- 24Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is Python and what are its common uses?
Python is a popular programming language used at companies like Google and universities. It is used for web backend code, data analysis, and scientific research.
Or swipe the card
24 cards
What is Python and what are its common uses?
Python is a popular programming language used at companies like Google and universities. It is used for web backend code, data analysis, and scientific research.
What is an advantage of Python's syntax?
Python has fairly simple syntax, making it easy to learn.
What is the role of Anaconda in installing Python?
Anaconda is a package manager that installs Python and Jupyter Notebook together, so you don't need to install them separately.
What are the two components of Jupyter Notebook?
The Jupyter Notebook server (command line interface) and the browser user interface (UI) connected to the server.
Which Python version should you install via Anaconda for this course?
Python 3 (the version with 3.something), not Python 2.
How do you launch Jupyter Notebook after installing Anaconda?
Open Anaconda Navigator and click 'Launch' under Jupyter Notebook.
What is a 'cell' in Jupyter Notebook?
A cell is a set of code. You can run the code in a cell using the run button, and the output appears below.
What does the print function do in Python?
It prints whatever is inside the parentheses to the output.
How are strings enclosed in Python?
Strings can be enclosed in either double quotes (") or single quotes (').
What happens if you forget to close a parenthesis or quote when using print?
You get an error.
Can the print function output numbers without quotes?
Yes, you can print numbers directly, e.g.,
print(3)outputs 3.How do you create a variable in Python?
Use the assignment operator
=:a = 1assigns the value 1 to variablea.In Python, is a variable like a box containing a value or a name tag?
A variable is more like a name tag that refers to a value, not a box.
How do you see what value a variable refers to?
Use
print(variable_name)without quotes around the variable name.Can a variable refer to a string?
Yes, variables can refer to strings as well as numbers.
Can two or more variables refer to the same value?
Yes, it is possible. For example,
d = 2andb = 2both refer to the same integer 2.How do you reassign an existing variable to a different value?
Use the assignment operator again:
b = 1afterb = 2makesbrefer to 1.What happens if you try to print a variable that hasn't been defined?
You get a NameError: the variable is not defined.
If you write
f = a, doesfrefer to the variableaor the valuearefers to?frefers to the value thatarefers to, not the variableaitself.After
a = 1; f = a; a = 2, what value doesfrefer to?fstill refers to 1.What is the naive way to swap two variables, and why does it fail?
Naive:
v1 = v2; v2 = v1. This fails because after the first line, both variables refer to the same value, so the second line makesv2refer to that same value (not the originalv1).What is the correct way to swap two variables using one temporary variable?
temp = v1 v1 = v2 v2 = temp
Can you swap variables using two temporary variables?
Yes:
temp1 = v1; temp2 = v2; v1 = temp2; v2 = temp1.Why is the single temporary variable swap pattern important to know?
It is a very common pattern used by programmers for swapping values.

Ask anything
We've read this whole study set, so questions about it get the best answers.