0

Plz explain your code i do not understand this code plz explain

def new_string(str): if len(str) >= 2 and str[:2] == "Is": return str return "Is" + str print(new_string("Array")) print(new_string("IsEmpty"))

13th Feb 2019, 6:18 PM
Gscode
Gscode - avatar
1 Odpowiedź
0
The if statement checks if the given value is 2 or more and if the first letter is I and the second letter’s s. If so the function will return the given value (function always stops after it returns). If the statement is false it will return Is + the given value.
14th Feb 2019, 9:33 PM
Juho Pesonen
Juho Pesonen - avatar