Gallery
Intro to Python
Share
Explore
Learn Python

icon picker
Variables, Expressions, and Statements

This section covers:
Storing values in variables
Evaluating expressions
Statements

Variables

Variables are containers for storing values. There are many different types of values, but some simple ones are strings (any combination of characters, like “apple” or “100%”), numbers (ex: 4 or 0.5), and booleans (true or false).
To start off, you can declare a variable with a specific name and a value.
After it’s declared, you can assign a different value to the variable, or you can use the current value of the variable.

Input Function

Python’s input function allows you to collect input from the user.
Here, it’s helpful to use a variable to store whatever the user inputs.

Expressions

An expression is a combination of values, variables, operators (ex: math operators like + - * /), and function calls (to be explained in a later section!) that can be evaluated to a single value.
Examples of expressions include:

Statements

A statement is like an instruction. We’ve already seen examples of statements: declaring and assigning a variable is a statement, and using print is also a statement.
This is different than an expression because a statement does something. However, you can use expressions in your statements. Here is an example of declaring a variable and assigning it to the evaluation of an expression:
In the upcoming sections, we will learn more about the other types of statements!
Task
Status
1
Learn about variables
Not Started
2
Learn about expressions
Not Started
3
Learn about statements
Not Started
No results from filter

Next Section ➡️


Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.