can I delete ":"? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

can I delete ":"?

the code is >>>name=input("č¾“å…„å§“å") č¾“å…„å§“å:郭靖 >>>print("{ }å“„å“„ļ¼Œå­¦å„½Python,äŗŗ见äŗŗēˆ±ļ¼".format(name[1:]))

26th Oct 2019, 11:21 AM
Yuan Ruo
Yuan Ruo - avatar
8 Respostas
+ 6
No, you can't, name[1:] is the whole string without the first element, but name[1] is just the second element
26th Oct 2019, 11:32 AM
Airree
Airree - avatar
+ 5
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"
26th Oct 2019, 12:09 PM
Russ
Russ - avatar
+ 3
You can remove the : using slice function, even though might not be the solution you searched for: name[slice(1, None)]
26th Oct 2019, 12:06 PM
Seb TheS
Seb TheS - avatar
+ 3
To delete ":", you must have a replace function on a string object. print("{} blahblahblah".format(name.replace(':',''))
27th Oct 2019, 2:49 PM
Name Omitted until I come back
+ 1
thank u,Airree but why this code without ":"? >>>print("{ }大侠ļ¼Œå­¦å„½Python,å¤§å±•ę‹³č„šļ¼".format(name[0]))
26th Oct 2019, 11:49 AM
Yuan Ruo
Yuan Ruo - avatar
0
No, name[1:] is the whole string except the first element, name[0] is just the first element
26th Oct 2019, 11:51 AM
Airree
Airree - avatar
- 1
Hi
27th Oct 2019, 6:20 PM
Freddy Nkade
Freddy Nkade - avatar
- 3
mirie love you
26th Oct 2019, 3:44 PM
Salem