我是一个Python业余爱好者,我正在创建一个非常基本的程序。我需要它将用户的输入格式化为标题格式,如下所示:
输入:你好
输出:Hello
这是我到目前为止所拥有的:
firstNameInput = input("Hello! What is your first name? \n")
firstName = firstNameInput.title
当我打印firstName时,我没有收到错误,但是它没有打印firstName,而是打印:
<built-in method title of str object at 0x0000000003EA60D8>
感谢您提前提供的任何帮助! :)
最佳答案
firstNameInput.title()
你缺少括号
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'
第一个是对该方法的引用,第二个是实际调用它。
关于Python 3.4 - 将字符串输入格式化为标题格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24717603/