gpt4 book ai didi

Python - 删除字符串中的空格

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:04 25 4
gpt4 key购买 nike

因此,我想在语句末尾打印一个带有感叹号的字符串,但最后一个单词和感叹号之间没有任何空格。例如:

name = raw_input('Insert your name: ')

现在,我想让 python 打印这样的东西:

Your name is John!

所以,我输入:

print 'Your name is', name, '!'

它返回给我:

Your name is John !

我想做的是去掉“John”和感叹号之间的空格。

有什么想法吗?

最佳答案

使用字符串格式:

print 'Your name is {}!'.format(name)

或:

print 'your name is %s!' %name

关于Python - 删除字符串中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10248660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com