Ask the Python output sequence.

Asked 2 years ago, Updated 2 years ago, 11 views

# Number of cases 1
def test_1():
    print ("Pass Point A")
    return 1


print ("through point D")

output = test_1()

print(output) 
#Number of cases 2
def test_2():
    print ("Pass Point A")
    return 1


output = test_2()

print ("through point D") 

print(output) 

The output value of "Pass Point D" and "Pass Point A" came out for the first time Number two is the opposite.

I understand the order of code for number 1, but why number 2 is different from number 1...

I don't know exactly why the result depends on where you declare the variable.

python

2022-09-22 11:07

1 Answers

As far as I know, output has 1 and the output order of A or D is related to the call order of the function, but not to print.


2022-09-22 11:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.