









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of objects in python programming language, focusing on points in 3d space, organizing data in folders, classes, constructors, referencing objects with variables, and methods. It covers the creation and manipulation of objects, their attributes, and methods, as well as the difference between mutable and immutable objects.
Typology: Slides
1 / 15
This page cannot be seen from the preview
Don't miss anything!










x 2. y 3. z 5.
x 2. y 3. z 5.
Point
class name x 2. y 3. z 5. id
§ Other types have literals § Example : 1 , "abc", True
§ Same name as the class § Example: Point(0, 0, 0) § Makes an object (manila folder) § Returns folder ID as its value
§ Creates a Point object § Stores object’s ID in p p id Variable stores ID not object instantiated object Point x 0. y 0. z 0. id
§ Can use in expressions § Can assign values to them
§ Example: p.x § Same syntax as accessing a variable in a module: math.pi
p id Point x 1. y 2. z 3. id
p = Point(0,0,0) q = p
p.x = 5. q.x = 7.
p q A: 5. B: 7. C: id D: I don’t know Point x 0. y 0. z 0. id id id
§ Method call looks like a function call preceded by a variable name: ⟨ variable ⟩.⟨ method ⟩(⟨ arguments ⟩) § Example: p.distanceFromOrigin() § Example: p.distanceTo(q)
§ ⟨ object ⟩.⟨ name ⟩ means “go to object and look for something called name .” § Python looks first in the object’s folder, then in the object’s class Point x 5. y 2. z 3. id init(x, y, z) distanceFromOrigin() distanceTo(other) Point p id
§ int, float, bool, str
x = 2. id(x)
§ They are immutable