Understanding Python Functions

Asked 2 years ago, Updated 2 years ago, 36 views

def(x):
    return x*2
    result=f(2)
    print(result)

When you enter , the number 4 does not appear in the result.What should I do?

python python3

2022-09-30 16:50

1 Answers

Python identifies a collection of codes by indentation.
The f(x) function definition and the utilization part of the function are defined at the same level of indentation, so f(x) could not be executed.

Wouldn't it be better to write it down as follows?

def(x):
  return x*2

result=f(2)
print(result)


2022-09-30 16:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.