【问题标题】:making first letter of input uppercase with split in python在 python 中使用 split 使输入的第一个字母大写
【发布时间】:2022-11-17 01:08:23
【问题描述】:

我记下了大部分代码,但在将每个单词的第一个字母大写后,我无法将字符串退回空格

这是我到目前为止所拥有的:

message = input('写一条短信。')

new_message = message.split()

胶水=“”

对于 new_message 中的项目:

胶水 += item[0].upper() + item[1:]

打印(胶水)

【问题讨论】:

  • 只是:message.capitalize() 怎么样?
  • 您可能会发现 this documentation 很有用。

标签: python for-loop input split uppercase


【解决方案1】:

尝试:

message.capitalize()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-11
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多