Objectives
- create comments in a Python program
- discuss some of the common data types in Python
- explain what literals are
- explain what identifiers, variables, and constants are
- list the Python operators
- create expressions in Python
The term "data type" refers to what type of data a variable, constant, or literal refers to. Some of the more commonly used data types in Python are:
Literals are explicit values in the source code, such as strings, numbers, etc. Literals can not be renamed or changed. Examples:
Variables are memory locations that are used to store data. These locations are given names so you can work with them more easily. Modules within programs may also be given names. These names are called identifiers. You get to choose the names for identifiers. Naming rules vary between languages, but some common rules are:
Constants are also memory locations that are used to store data. The difference between variables and constants is that constants do not change value once they are set. Variables can be modified.
Reserved words in Python 3.6:
and | as | assert | break | class |
continue | def | del | elif | else |
except | False | finally | for | from |
global | if | import | in | is |
lambda | None | nonlocal | not | or |
pass | raise | return | True | try |
while | with | yield |
The following are operators in Python 3.6:
+ | - | * | ** | / | // | % | @ | << | >> |
& | | | ^ | ~ | < | > | <= | >= | == | != |
Expressions are pieces of code that can be evaluated to get a value. Some examples are:
get hours and rate gross = hours * rate display gross
hours = float(input("Enter hours: ")) rate = float(input("Enter rate: ")) gross = hours * rate print("Total: ", gross)