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 ...
Get Practical Programming, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.