Dsaa 20
Dsaa 20
to a specific value within our program. For example, the literal 6 denotes any object
with the integer value of 6.
x = 6
This creates an int object containing the value 6. It also points the reference called
x at this object as pictured in Fig. 1.2. All assignments in Python point references at
objects. Any time you see an assignment statement, you should remember that the
thing on the left side of the equals sign is a reference and the thing on the right side is
either another reference or a newly created object. In this case, writing x = 6 makes
a new object and then points x at this object.
Other literal values may be written in Python as well. Here are some literal values
that are possible in Python.
Most of the time, when an object is created, it is not created from a literal value.
Of course, we need literal values in programming languages, but most of the time
we have an object already and want to create another object by using one or more
existing objects. For instance, if there is a string like ‘6’ and want to create an int
object from that string, you write code like that in Listing 1.1.