问题
I'm a bit of a python amateur and I'm creating an extremely basic program. I need it to format a user's input into title format like so:
Input: hello
Output: Hello
This is what I have so far:
firstNameInput = input("Hello! What is your first name? \n")
firstName = firstNameInput.title
When I come to print firstName I get no error, however instead of printing firstName it prints:
<built-in method title of str object at 0x0000000003EA60D8>
Thanks for any help in advance! :)
回答1:
firstNameInput.title()
you are missing parens
In [1]: s = "hello world"
In [2]:print (s.title)
Out[2]:<built-in method title of str object at 0x7fbea30830b0>
In [3]: s.title()
Out[3]: 'Hello World'
The first is a reference to the method, the second is actually calling it.
来源:https://stackoverflow.com/questions/24717603/python-3-4-formatting-string-input-into-title-format