I am trying to print a string in all uppercase letters. When I run the print command it prints the type of x and the location.
Why does it print the operation instead of the result?
x = 'bacon'
x = x.upper
print x
>>>
<built-in method upper of str object at 0x02A95F60>
upper (and all other methods) is something like "function ready to use", that way you can do:
x = 'bacon'
x = x.upper
print x()
But the most common to see, and the way I think you want is:
x = 'bacon'
x = x.upper()
print x
"Ridiculous" example using lambda:
upper_case = lambda x: x.upper()
print(upper_case) # <function <lambda> at 0x7f2558a21938>
print(upper_case('bacon')) # BACON
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