Introduction
Numbers and character strings are important data types in any Python program- These are the fundamental building blocks we use to build more complex data structures.
Variables
A variable is a named storage location in a computer program.- There are many different types of variables, each type used to store different things.
- You ‘define’ a variable by telling the compiler:
- What name you will use to refer to it.
- The initial value of the variable.
- You use an assignment statement (=) to place a value into a variable.
Variable Definition
To define a variable, you must specify an initial value.
****
The assignment statement
- Use the assignment statement '=' to place a new value into a variable cansPerPack = 6 # define & initializes the variable cansPerPack
- The left-hand side of an assignment statement consists of a variable
- The right-hand side is an expression that has a value
- Beware: The “=“ sign is NOT used for comparison:
- It copies the value on the right side into the variable on the left side
- You will learn about the comparison operator in the next chapter
Assignment syntax
*****
No comments:
Post a Comment