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). Variable names are case sensitive, so ph and pH are two different names.

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 ...

Get Practical Programming, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.