+ 1
Can someone please explain to me why this works and other ways to do this using re?
Regular expressions We need to create a number formatting system for a contacts database. Create a program that will take the phone number as input, and if the number starts with "00", replace them with "+". The number should be printed after formatting. Sample Input 0014860098 Sample Output +14860098 Notice that here you shouldn't convert the input string to integer, because you will work with symbols. Code: import re num = input() print(re.sub(r"^00","+",num))
1 Réponse
+ 1
It substitutes two 0's with a '+' IF the 0's are at the start of the number. The important part is the carat. It tests for items only at the beggining.