Work with values and variables
Name values, use common types and combine simple expressions.
- Assign variables and print values and calculations.
A variable gives a value a name. Python uses types such as integers (int), decimals (float), text (str) and true/false values (bool). The = operator assigns a value to a variable.
name = "Ada"
years = 10
print(name, years)Ada 10
Variable names are case-sensitive and should describe their values. print accepts several values and separates them with spaces by default. Use type(value) to inspect a value’s type.
Key takeaways
Assign variables and print values and calculations.
Read the output to check what your program did.
Keep indentation consistent in Python blocks.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write Python
Write Python in the editor and run it against sample inputs. Python runs locally in your browser using a WebAssembly runtime.
Double it
Read an integer from input(), convert it to an integer, then print twice its value.
- Input 4
- Input -3
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…