+ 2
should not be str
It is a number between ""s so it is a string
5 Antworten
+ 5
Maybe the question you got was something like this...?
Replace 9 with 0 in the string num
import re
num = "07987549836"
pattern = r"9"
num = re.sub(pattern, "0", num)
print(num)
It's sort of confusing because unlike the example, the fourth line reassigns a value to variable num. However, the fourth line is basically saying to substitute the pattern (9) with (0) in the original num variable.
Sorry if i didng manage to answer your question though...
+ 1
num = "07987549836"
pattern = r"9"
num = re.sub(pattern, "0",num)
+ 1
Replace 9 with 0 in the string num
Correct answer:
import re
num = "07987549836"
pattern = r"9"
num = re.sub(pattern, "0", num)
print(num)
It is a challenge cause you're getting towards the end of the thing. Good luck!
0
num = "07987549836"
pattern = r"9"
num = re.sub(pattern, "0",num)
- 2
?