Skip to main content
Contents Index
Search Book
Search Results:
No results.
Readability settings Prev Up Next Scratch ActiveCode Profile
title here
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 2.6 Expressions
An
expression is a combination of values, variables, and operators. A value all by itself is considered an expression, and so is a variable, so the following are all legal expressions (assuming that the variable
x has been assigned a value):
If you type an expression in interactive mode, the interpreter
evaluates it and displays the result:
But in a script, an expression all by itself doesn’t do anything! This is a common source of confusion for beginners.
Type the following statements in the Python interpreter to see what they do:
Activity 2.6.1 .
Which of the following is an expression?
5
An expression is a combination of values, variables, and operators.
x = 5
An expression is a combination of values, variables, and operators.
x + 1
An expression is a combination of values, variables, and operators.
all of the above
All of the above are correct! An expression is a combination of values, variables, and operators.
none of the above
An expression is a combination of values, variables, and operators.
Activity 2.6.2 .
Click on the expression(s) that will **not** return a value when typed in an interpreter.
Try typing these expressions in a python interpreter to see what they do.
12
x = 73
x + 12
x += 52 >#using += is the same as writing out x = x + 52
You have attempted
of
activities on this page.