0

About Python MCQ

import re str = 'sololearn123' print(re.sub(r'[aA-zZ]',",str)) How the output is 123?

15th Oct 2022, 11:24 AM
Mustakim Rahman
Mustakim Rahman - avatar
8 Réponses
+ 11
Mustakim Rahman the code as it is given is not completely correct: print(re.sub(r'[aA-zZ]',",str)) ^ the marked character is 1 double quote >"<, but should be 2 single quotes >''< since it represents an empty string. the character group [aA-zZ] is working, but could be written also like: [a-zA-Z].
15th Oct 2022, 3:55 PM
Lothar
Lothar - avatar
+ 9
Sandeep , i copied the code and pasted it in my local editor, where i could see a difference between 2 single quotes and 1 double quote.
17th Oct 2022, 10:49 AM
Lothar
Lothar - avatar
+ 8
Sandeep , i am using pydroid on my android device. the font i am using is listed as *Monospace*
18th Oct 2022, 8:43 PM
Lothar
Lothar - avatar
+ 5
thanks Lothar 👍 I guess font choice really matters in programming
19th Oct 2022, 5:39 AM
Sandeep
Sandeep - avatar
+ 4
Lothar how did you find it's a double quote? It looks exactly similar to two single quotes!
15th Oct 2022, 5:04 PM
Sandeep
Sandeep - avatar
+ 4
Lothar which code editor do you use?
17th Oct 2022, 1:29 PM
Sandeep
Sandeep - avatar
+ 3
re.sub() function replaces one or many matches with a string in the given text. The search and replacement happens from left to right.
15th Oct 2022, 12:09 PM
JaScript
JaScript - avatar
+ 2
Lothar good catch😎! Python error message was useless for this one...🙃 Perhaps font choice makes it easier or harder to spot. like l or 1,0,O,',` etc...
16th Oct 2022, 10:45 AM
Bob_Li
Bob_Li - avatar