What will be the output of the following Python code? [code]import re s = 'abc123 xyz666 lmn-11 def77' re.sub(r'\b([a-z]+)(\d+)', r'\2\1:',

Kim Thu Đoàn

New member
What will be the output of the following Python code?
Code:
import re
s = 'abc123 xyz666 lmn-11 def77'
re.sub(r'\b([a-z]+)(\d+)', r'\2\1:', s)
A. ‘123abc: 666xyz: lmn-11 77def:’
B. ‘77def: lmn-11: 666xyz: 123abc’
C. ‘abc123:’, ‘xyz666:’, ‘lmn-11:’, ‘def77:’
D. ‘abc123: xyz666: lmn-11: def77’
 
Answer: a
Explanation: The function re.sub returns a string produced by replacing every non overlapping occurrence of the first argument with the second argument in the third argument. Hence the output is: ‘123abc: 666xyz: lmn-11 77def:’
 

Tìm kiếm

Back
Top