Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Method overriding
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Python=== In [[Python (programming language)|Python]], when a subclass contains a method that overrides a method of the superclass, you can also call the superclass method by calling {{Python|super(Subclass, self).method}}<ref name="python-3-super">{{Python|super().method}} in Python 3 - see https://docs.python.org/3/library/functions.html#super {{Webarchive|url=https://web.archive.org/web/20181026035007/https://docs.python.org/3/library/functions.html#super |date=2018-10-26 }}</ref> instead of {{Python|self.method}}. Example: <syntaxhighlight lang="python"> class Thought: def __init__(self) -> None: print("I'm a new object of type Thought!") def message(self) -> None: print("I feel like I am diagonally parked in a parallel universe.") class Advice(Thought): def __init__(self) -> None: super(Advice, self).__init__() def message(self) -> None: print("Warning: Dates in calendar are closer than they appear") super(Advice, self).message() t = Thought() # "I'm a new object of type Thought!" t.message() # "I feel like I am diagonally parked in a parallel universe. a = Advice() # "I'm a new object of type Thought!" a.message() # "Warning: Dates in calendar are closer than they appear" # "I feel like I am diagonally parked in a parallel universe. # ------------------ # Introspection: isinstance(t, Thought) # True isinstance(a, Advice) # True isinstance(a, Thought) # True </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)