Home > front end >  In python, how can I jump to a def?
In python, how can I jump to a def?

Time:11-25

I want to jump from def number1 to def number2. I tried this:

def number1():
    print("from here to ")
    number2()
number1()
def blablabla():
    print("blablabla")
blablabla()
def number2():
    print("here")
number2()

but I received this error:

Traceback (most recent call last):
  File "C:\Users\i5 9400f\Documents\projetos python\test.py", line 4, in <module>
    number1()
  File "C:\Users\i5 9400f\Documents\projetos python\test.py", line 3, in number1
    number2()
    ^^^^^^^
NameError: name 'number2' is not defined. Did you mean: 'number1'?
from here to 

Process finished with exit code 1

I tried using the number2() it did not work

CodePudding user response:

Python just run your code from top to bottom sequentially so if you try to access to something that is only defined later you won't succeed. What you need to do is to define all the functions first then call them later :

def number1():
    print("from here to ")
    number2()

def blablabla():
    print("blablabla")

def number2():
    print("here")

number1()
blablabla()
number2()

CodePudding user response:

def number1():
    print("from here to ")
    number2()

def number2():
    print("here")

def blablabla():
    print("blablabla")

number1()
blablabla()
number2()

###Before runnıng def functıons, you should put them at the top of your processes

  • Related