【问题标题】:How to repeat the first letter twice using a str?如何使用str重复第一个字母两次?
【发布时间】:2019-05-09 18:40:21
【问题描述】:

我的目标是让用户给程序一句话;完成后,我希望它使用 str 重复第一个字母两次。

这是我目前所拥有的:

phrase = input("Enter a word: ")

print (phrase[0])

我希望输出的示例:

Enter a word: Hello
HH

Enter a word: Grey 
GG

Enter a word: Olives
OO

【问题讨论】:

  • print (phrase[0] * 2)

标签: python string python-3.x python-2.7


【解决方案1】:

试试这个:

phrase = input("Enter a word: ")

print (phrase[0]+phrase[0])

一般来说,添加两个字符串会将它们连接起来。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-11
    • 2013-09-24
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2018-12-12
    相关资源
    最近更新 更多