mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): explain callable() in dynamic attributes lecture (#67360)
This commit is contained in:
+2
@@ -97,6 +97,8 @@ for attr in dir(person):
|
||||
# name: John Doe
|
||||
```
|
||||
|
||||
In the loop above, `callable()` is a built-in function that returns `True` if the object passed to it can be called like a function or method, and `False` otherwise. By checking `not callable(getattr(person, attr))`, the loop skips over methods and only prints the data attributes like `name` and `age`.
|
||||
|
||||
The `setattr()` function lets you create a new attribute or update an existing one dynamically. The syntax looks like this:
|
||||
|
||||
```python
|
||||
|
||||
Reference in New Issue
Block a user