...

/

Puzzle 7: Explanation

Puzzle 7: Explanation

Let’s learn about how attributes work in Python.

We'll cover the following...

Try it yourself

Try executing the code below to verify the result:

Press + to interact
next_uid = 1
class User:
def __init__(self, name):
global next_uid
self.name = name
self.__id = next_uid
next_uid += 1
u = User('daffy')
print(f'name={u.name}, id={u.__id}')

Explanation

Unlike other languages, Python does not have private and protected attributes. By convention, ...

Access this course and 1400+ top-rated courses and projects.