i.e. x = int
I understand that this will make x an integer if it is not already one, but I'd like to understand the process behind this. In particular, I'd like to know what int is (as opposed to int()). I know that int() is a function, but I'm not sure what int is. Links to documentation about int would be helpful since I couldn't find any.
Imagine you had a function called func
def func():
print("hello from func")
return 7
If you then assigned func to x you are assigning the function itself to x not the result of the call
x = func # note: no ()
x() # calls func()
y = x() # y is now 7
You're looking at a very similar thing with int in this context.
x = int
y = x('2') # y is now 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With