Python 3.4 - 将字符串输入格式化为标题格式

时间:2014-07-12 21:44:46

标签: python python-3.4

我有点像业余爱好者,我正在创建一个非常基本的程序。我需要它将用户的输入格式化为标题格式,如下所示:

输入:hello

输出:Hello

这是我到目前为止所做的:

firstNameInput = input("Hello! What is your first name? \n")

firstName = firstNameInput.title

当我来打印firstName时,我没有得到任何错误,但是打印firstName而不是打印:

<built-in method title of str object at 0x0000000003EA60D8>

提前感谢您的帮助! :)

1 个答案:

答案 0 :(得分:1)

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'

第一个是对方法的引用,第二个是实际调用它。