Constants
- Fixed values such as numbers, letters, and strings, are called constants because their value does not change
- Numeric constants are as you expect
- String constants use single quotes(’) or double quotes(”)
>>> print(12)
123
>>> print(98.6)
98.6
>>> print('Hello World')
Hello World
Reserved Words
You cannot use reserved words as variable names / identifiers
Variables
- A variable is a named place in the memory where a programmer can store data and later retrieve the data using the variable “name”
- Programmers get to choose the names of the variables
- You can change the contents of a variable in a later statement
Python Variable Name Rules
- Must start with a letter or underscore _
- Must consist of letters, numbers, and underscores
- Case Sensitive
Good : spam eggs spam23 _speed
Bad : 23spam #sign var.12
Different : spam Spam SPAM
Mnemonic Variable Names
- Since we programmers are given a choice in how we choose our variable names, there is a bit of “best practice”
- We name variables to help us remember what we intend to store in them (mnemonic = “memory aid”)
- This can confuse beginning students because well-named variables often “Sound” so good that they must be keywords
Assignment Statements
- We assign a value to a variable using the assignment statement (=)
- An assignment statement consists of an expression on the right=hhand side and a variable to store the result