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 8395133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:13:19+00:00 2026-06-09T20:13:19+00:00

In Python why a function called main doesn’t have any special significance like it

  • 0

In Python why a function called main doesn’t have any special significance like it has in C and Java?

What if a programmer switches from C or Java to Python. Should he keep
using main in Python also like in C or Java as it’s his style now to do
the programming or in a broad sense it is somehow harmful for doing
programming in Python?

Edit: I have gone through this article where it was mentioned by a very good example why first time programmers should refrain main in python main in python harmful.

  • 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-06-09T20:13:21+00:00Added an answer on June 9, 2026 at 8:13 pm

    You should also be asking, why in C and Java does main have a special significance. It’s just a choice on the part of the language designer. main could well have been called start or begin but somebody chose main and it stuck.

    In Python there is no reason why you can’t call a function main and have it be the start point of your program. However, Python has its own syntax to identify whether a certain file is the equivalent of main:

    __name__ == "__main__"
    

    This is typically wrapped as part of an if and could simply have a single line within calling your main function that actually starts your program.

    Part of the design of Python and many (all?) scripting languages is that code can simply be written inline. You don’t have to wrap everything in a function. As such, many simple scripts do not require any functions at all. A cron job for example that rotates log files could just be written as a block of code in a python file with no functions being defined.

    In that scenario, the main method just isn’t required.

    Not requiring a main in many ways makes the language more flexible, especially for simpler tasks.

    ADDENDUM:

    To add some context to your edit. That article presents a very poor argument. In reality function name collisions are not uncommon as there are many modules that do the same or similar things (not so much in core but as soon as you start using pip you’ll encounter the odd collision). Therefore it is beneficial to use descriptive function names and avoid ever doing a from foo import *.

    In the same way that C++ programmers generally consider it bad form to pollute your namespace with using namespace std, Python programmers typically consider it bad form to pollute your namespace with import *, especially as it can cause a snowball effect if used everywhere.

    Finally, you’re unlikely to call 2 functions in your program main. You’re much more likely to have name collisions elsewhere. The real danger is the wildcard import, not the main function.

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

Sidebar

Related Questions

I have a python function that gets an array called row. Typically row contains
I have the following function in a Python module called dictbuilder.py: def my_dictbuilder(reader_o, writer):
Factor appears to have a main method like any C-based language: #! /usr/bin/env factor
The __repr__ function of python is fancy as it is called when print OBJECT
I'm using Python's max function to find the largest integer in a dictionary called
While I'm going through Python code and seeing functions called, I notice things like
I have a python function that makes a subprocess call to a shell script
I have a python function that randomize a dictionary representing a position specific scoring
Possible Duplicate: “main” function in Lua? In Python, you can check if a script
I have an application in python with a custom main loop (I don't believe

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.