mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
[python/en] Update class example on invoking static methods from class instance.
This commit is contained in:
parent
dd6624856b
commit
141eaec78c
@ -773,9 +773,8 @@ if __name__ == '__main__':
|
|||||||
# Call the static method
|
# Call the static method
|
||||||
print(Human.grunt()) # => "*grunt*"
|
print(Human.grunt()) # => "*grunt*"
|
||||||
|
|
||||||
# Cannot call static method with instance of object
|
# Static methods can be called by instances too
|
||||||
# because i.grunt() will automatically put "self" (the object i) as an argument
|
print(i.grunt()) # => "*grunt*"
|
||||||
print(i.grunt()) # => TypeError: grunt() takes 0 positional arguments but 1 was given
|
|
||||||
|
|
||||||
# Update the property for this instance
|
# Update the property for this instance
|
||||||
i.age = 42
|
i.age = 42
|
||||||
|
Loading…
Reference in New Issue
Block a user