Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 838289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:16:51+00:00 2026-05-15T05:16:51+00:00

I am new to Python so please don’t flame me if the question is

  • 0

I am new to Python so please don’t flame me if the question is too basic 🙂

I have read that Python is executed from top – to – bottom.

If this is the case, why do programs go like this:

def func2(): 
    pass

def func1():
    func2()

def func():
    func1()

if __name__ == '__main__':
    func()

So from what I have seen, the main function goes at last and the other functions are stacked on top of it.

Am I wrong in saying this? If no, why isn’t the main function or the function definitions written from top to bottom?

EDIT: I am asking why I can’t do this:

if __name__ == '__main__':
    func()

def func1():
    func2()

Isn’t this the natural order? You keep on adding stuff at the bottom, since it is executed from top to bottom.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:16:52+00:00Added an answer on May 15, 2026 at 5:16 am

    The defs are just creating the functions. No code is executed, other than to parse the syntax and tie functions to those names.

    The if is the first place code is actually executed. If you put it first, and call a function before it is defined, the result is a NameError. Therefore, you need to put it after the functions are defined.

    Note that this is unlike PHP or JavaScript, where functions are ‘hoisted’ – any function definitions are processed and parsed before everything else. In PHP and JavaScript, it’s perfectly legal to do what you are saying and define functions in the source lower down than where they are called. (One detail in JS is that functions defined like function(){} are hoisted, while functions defined like var func1=function(){}; are not. I don’t know how it works with anonymous functions in PHP 5.3 yet).

    See, in this, cat() will print correctly, and yip() gives you a NameError because the parser hasn’t gotten to the definition of yip() at the time you call it.

    def cat():
      print 'meowin, yo'
    
    cat()
    
    yip()
    
    def yip():
      print 'barkin, yall'
    

    meowin, yo
    Traceback (most recent call last):
    File “cat.py”, line 5, in
    yip()
    NameError: name ‘yip’ is not defined

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok It's because the link beetween the file owners and… May 16, 2026 at 12:04 pm
  • Editorial Team
    Editorial Team added an answer As you might see If you read that, screen size… May 16, 2026 at 12:04 pm
  • Editorial Team
    Editorial Team added an answer This sounds like somone has used names. You can modify… May 16, 2026 at 12:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am new to Python so please don't flame me if I ask something
I am new to Python (I dont have any programming training either), so please
I am new to Python - be forewarned! I have a template class that
I'm new to Python and I have been trying to search through html with
I'm still relatively new to Python, so if this is an obvious question, I
I know a bunch of scripting languages, (python, ruby, lua, php) but I don't
I'm somewhat new to Python, Django, and I'd like some advice on how to
I'm new to Python, and I'm using Google App Engine to build a simple
I'm kind of new to Python and I wonder if there is a way
I'm new to python and django, and when following the Django Book I learned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.