简体   繁体   English

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

[英]Python 3.4 - Formatting String Input into Title format

I'm a bit of a python amateur and I'm creating an extremely basic program. 我是一名python业余爱好者,并且正在创建一个非常基本的程序。 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: 当我来打印firstName时,我没有收到任何错误,但是不是打印firstName而是打印:

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

Thanks for any help in advance! 感谢您的任何帮助! :) :)

firstNameInput.title() you are missing parens 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. 第一个是对该方法的引用,第二个实际上是在调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM