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