# shadowing class attributes

what will this print

```python
>>> class User: 
...    id = 1 

>>> u = User() 
>>> u.id = 89 
>>> User.id = 98 
>>> print(u.id)
89
```

This code will print the value 89.

Here's a step-by-step breakdown of what happens:

1. The `User` class is defined with a class attribute `id` initialized to 1.
    
2. An instance of the `User` class is created and assigned to the variable `u`.
    
3. The instance `u` is modified by assigning the value 89 to its `id` attribute. This creates an instance attribute `id` for `u` that shadows the class attribute.
    
4. The class attribute `id` is modified by assigning the value 98 to it.
    
5. When `print(`[`u.id`](http://u.id)`)` is called, it accesses the instance attribute `id` of `u`, which has the value 89. Hence, the output will be 89.
    

In Python, you can access the class attribute `id` with an instance `u` of the `User` class using dot notation ([`u.id`](http://u.id)). However, if the instance has its own attribute with the same name, it will shadow the class attribute, and the value of the instance attribute will be retrieved instead.

In the code snippet you above, you assign a value of `89` to [`u.id`](http://u.id), which creates an instance attribute that shadows the class attribute `id`. When you print [`u.id`](http://u.id), it retrieves the value of the instance attribute, which is `89`.

**If you must access the class id using the class instances:**

If you specifically want to access the class attribute `id` using the instance `u` (rather than directly using the class name), you can use the `__class__` attribute of the instance. Here's an example:

```python
class User:
    id = 1

u = User()
u.id = 89
User.id = 98

print(u.__class__.id)  # Output: 98
```
