Str doesn't have del or pop. I just want to take out the characters in the middle of the string, for example,
To remove only the middle "M" from the string "EXAMPLE", which of the following methods would you recommend?
Also, when checking the end of the string, it was '\0'
in c, but I wonder how it is done in Python
Python has two main options.
newstr = oldstr.replace("M", "")
midlen = len(oldstr)/2
newstr = oldstr[:midlen] + oldstr[midlen+1:]
And in C, the end of the string was always '\0'
, but in Python, there is no character that specifies the end, so we check it with len() or with an interpreter
mystr = "hello C world"
for i in range(len(mystr)):
print(mystr[i])
#or Baro Eaterate
for i in mystr:
print(i)
© 2024 OneMinuteCode. All rights reserved.