def func(x=2):
if x<=0:
return
print(x)
for x in range(3):
func()
2
2
2
When I did it, this value came out, but I thought I was misunderstanding something, so I wanted to hear the answers from masters, so I posted a question. As I understand it,
Put 2 in the function Since 2 is greater than 0, print without return. Since 2 is substituted for x, 2 is output as shown in the above equation.
python
To give you a simple answer, since the input parameter was not explicitly substituted for the function, the default value of 2 was substituted and executed.
In order to solve the problem, the variables must be explicitly substituted as shown below.
for x in range(3):
func(x)
© 2024 OneMinuteCode. All rights reserved.