+ 12
Why does it print only the second line "xxxxxxx"?
4 Réponses
+ 7
You defined print_text function twice, so when you call print_text function it has the second value: print('xxxxx'). If you want to print two lines you should define two functions with different names and call them both.
+ 1
You could also remove line 10, so you have only one function definition for print_text(), which prints two lines.
def print_text():
print("Hello world!")
print("xxxxxxx")
+ 1
You re-defined function print_text() (1st time started at line #8, 2nd time at line #10). The program will run with the latest definition of print_text(), printing only "xxxxxxx".
Let's try remove line #10 and see if it works as you expected.
0
def decor(func):
def wrap():
print("============")
func()
print("============")
return wrap
def print_text():
print("Hello world!")
print("xxxxxxx")
print_text = decor(print_text)
print_text();
#this should print both lines.