DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
Pip = "cat" Variable assigned to a string

Age = 9 Variable assigned to an integer

Chill = True Variable assigned to a Boolean

Variable1 = Variable2 Variable assigned to another variable

Data Types


Everything in Python is an object, and depending on the
type of object, there are certain characteristics that you
must be aware of when trying to determine the correct
action you can perform on them. In Python, whenever
you create an object, you are assigning that object an ID
that Python uses to recall what is being stored. This
mechanism is used to point to the memory location of
the object in question and allows you to perform actions
on it, such as printing its value. When the object is
created, it is assigned a type that does not change. This
type is tied to the object and determines whether it is a
string, an integer, or another class.


Within these types, you are allowed to either change the
object (mutable) or are not allowed to change the object
(immutable) after it has been created. This doesn’t mean
that variables are not able to be changed; it means that
most of the basic data types are not able to be modified
but need to be replaced (or assigned, in Python speak)
with another value. You can’t just add a character at the
end of a string value, for example. You have to instead
reassign the whole string if you want to change it. This
mutable/immutable concept will make more sense as
you interact with various data types in programs. Python
treats these two types of objects differently, and each has
nuances that you must work around as you build your
Python programs. To make it simple, think of immutable

Free download pdf