Variables and Computer Memory: Remembering Values
Like mathematicians, programmers frequently name values so that they can use them later. A name that refers to a value is called a variable. In Python, variable names can use letters, digits, and the underscore symbol (but they can’t start with a digit). For example, X, species5618, and degrees_celsius are all allowed, but 777 isn’t (it would be confused with a number), and neither is no-way! (it contains punctuation).
You create a new variable by assigning it a value:
| | >>> degrees_celsius = 26.0 |
This statement is called an assignment statement; we say that degrees_celsius is assigned the value 26.0. That makes degrees_celsius refer to the value 26.0. We can use variables anywhere ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access