Python 3.4 - 将字符串输入格式化为标题格式 [英] Python 3.4 - Formatting String Input into Title format
本文介绍了Python 3.4 - 将字符串输入格式化为标题格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有点 Python 业余爱好者,我正在创建一个非常基本的程序.我需要它将用户的输入格式化为标题格式,如下所示:
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:
输入:你好
输出:你好
这是我目前所拥有的:
firstNameInput = input("你好!你叫什么名字?\n")
firstName = firstNameInput.title
当我打印 firstName 时,我没有收到任何错误,但是它打印的不是 firstName:
When I come to print firstName I get no error, however instead of printing firstName it prints:
<0x0000000003EA60D8处str对象的内置方法标题>
提前感谢您的帮助!:)
Thanks for any help in advance! :)
推荐答案
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'
第一个是对方法的引用,第二个是实际调用它.
The first is a reference to the method, the second is actually calling it.
这篇关于Python 3.4 - 将字符串输入格式化为标题格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文