can I delete ":"? | Sololearn: Learn to code for FREE!


can I delete ":"?

the code is >>>name=input("输入姓名") 输入姓名:郭靖 >>>print("{ }哥哥,学好Python,人见人爱!".format(name[1:]))

10/26/2019 11:21:41 AM

Yuan Ruo

10 Answers

New Answer


No, you can't, name[1:] is the whole string without the first element, but name[1] is just the second element


You can delete it but you'll get a different result. : is for slicing, so If name = "xiao" name[1:] would be "iao" But name[1] would be "x"


Yes, thanks


Mirielle🐶 [Inactive] I know you made a simple typo but, as it's potentially a confusing one, I feel I should correct. If name = "xiao" name[1:] is "iao" name[1] is "i"


You can remove the : using slice function, even though might not be the solution you searched for: name[slice(1, None)]


To delete ":", you must have a replace function on a string object. print("{} blahblahblah".format(name.replace(':',''))


thank u,Airree but why this code without ":"? >>>print("{ }大侠,学好Python,大展拳脚!".format(name[0]))


No, name[1:] is the whole string except the first element, name[0] is just the first element



mirie love you