Articles
Screencasts
Exercises
Training
Pastebin
Gift
/
Sign Up
Sign In
__new__ is odd and should RARELY be used.
Editable Code
"""__new__ is odd and should RARELY be used.""" class cube: """A class that acts like a function.""" def __new__(cls, n): return n**3 # Return a new integer instead of a new cube instance if __name__ == "__main__": print(cube(5)) print(cube(3), type(cube(3))) # Calling the "cube" class returns an integer 😯
969 views
Copy
Code copied
Run
in Browser
pym.dev/p/28r9m/
URL copied
Need to share some Python code?
New Python snippet