0

About Python MCQ

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

15th Oct 2022, 11:21 AM
Mustakim Rahman
Mustakim Rahman - avatar
1 Resposta
+ 1
Hi, Mustakim Rahman ! re.sub replace whats in the first argument with that in the second argunent. So it takes the substring with all characters aA-zZ an replace it with nothing. Left is the numbers (digits). # As an example: import re str = 'soloLearn123' print(re.sub(r'[A-Z]', 'Q', str)) # becomes: soloQearn123 # As an second example: import re str = 'soloLearn123' print(re.sub(r'[a-z]', '', str)) # becomes: L123
15th Oct 2022, 11:31 AM
Per Bratthammar
Per Bratthammar - avatar