A
A
Alexander Bureyko2021-10-20 22:13:56
Python
Alexander Bureyko, 2021-10-20 22:13:56

Why is this code throwing an error?

Hello, I am a beginner in programming. I would like to understand why in the first code it does not give an error, but in the second it does?

x = 50
def func(x):
    print('x равен', x)
    x = 2
    print('замена локального x на', x)
func(x)
print('x по прежнему', x)


second code

x = 50
def func():
    print('x равен', x)
    x = 2
    print('замена локального x на', x)
func()
print('x по прежнему', x)

61706c74102af901824489.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question