0% found this document useful (0 votes)
40 views

2.1.2 Variables and Assignment: Chapter 2. Introduction To Python

This document discusses variables and assignment in Python. It explains that variables provide names that are associated with objects, and that assignment statements bind names to the left of the equals sign to the object represented by the expression to the right. It also notes that a variable is just a name and that rebinding a variable does not affect other variables bound to the same original object.

Uploaded by

ZhichaoWang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

2.1.2 Variables and Assignment: Chapter 2. Introduction To Python

This document discusses variables and assignment in Python. It explains that variables provide names that are associated with objects, and that assignment statements bind names to the left of the equals sign to the object represented by the expression to the right. It also notes that a variable is just a name and that rebinding a variable does not affect other variables bound to the same original object.

Uploaded by

ZhichaoWang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Chapter 2.

Introduction to Python
using parentheses to group subexpressions, e.g., (x+y)*2 first adds x and y, and
then multiplies the result by 2.
The operators on type bool are:

a and b is True if both a and b are True, and False otherwise.

a or b is True if at least one of a or b is True, and False otherwise.

not a is True if a is False, and False if a is True.

2.1.2 Variables and Assignment


Variables provide a way to associate names with objects. Consider the code
pi = 3
radius = 11
area = pi * (radius**2)
radius = 14

It first binds the names pi8 and radius to different objects of type int. It then
binds the name area to a third object of type int. This is depicted in the left
panel of Figure 2.2.

Figure 2.2 Binding of variables to objects


If the program then executes radius = 11, the name radius is rebound to a
different object of type int, as shown in the right panel of Figure 2.2. Note that
this assignment has no effect on the value to which area is bound. It is still
bound to the object denoted by the expression 3*(11**2).
In Python, a variable is just a name, nothing more. Remember thisit is
important. An assignment statement associates the name to the left of the =
symbol with the object denoted by the expression to the right of the =.
Remember this too. An object can have one, more than one, or no name
associated with it.

8 If you believe that the actual value of is not 3, youre right. We even demonstrate that
fact in Chapter 15.

11

You might also like