Python if __name__ == '__main__' ❓

preview_player
Показать описание
python if __name__ == '__main__' name == main tutorial example explained

#python #name #main

# ***********************************
# if __name__ == '__main__'
# ***********************************

# y tho?
# 1. Module can be run as a standalone program
# or
# 2. Module can be imported and used by other modules

# Python interpreter sets "special variables", one of which is __name__
# Python will assign the __name__ variable a value of '__main__' if it's
# the initial module being run

def main():
print("Hello!")

if __name__ == '__main__':
main()

# ***********************************

Bro Code merch store 👟 :
===========================================================
===========================================================
Рекомендации по теме
Комментарии
Автор

At 2:47 onward, I began to actually grasp what this concept might mean. All other videos I watched did not help until I found this one. I owe you the career I make later in life!!

fireemblem
Автор

#
# if __name__ == '__main__'
#

# y tho?
# 1. Module can be run as a standalone program
# 2. Module can be imported and used by other modules

# Python interpreter sets "special variables", one of which is __name__
# Python will assign the __name__ variable a value of '__main__' if it's
# the initial module being run

def main():
print("Hello!")


if __name__ == '__main__':
main()

#

BroCodez
Автор

watched so many other videos but still didn't get a clarity on what that code meant. But you explained it very well. Thank you.

jag
Автор

You explained this so much clearer than the other videos I watched. Thank you!

SuperSquall
Автор

Thank you. I never ever was able to understand this topic so clearly till now.

AlokTP
Автор

Dude! Thank you! I was so confused in my textbook. Always come to your channel to understand.

adrianarreguin
Автор

I've missed watching your videos. I am so happy that I have a reason to again

universalponcho
Автор

So, I've just realized that it is needed to be used if you wanna use some function or maybe a variable from a file and don't run it entirely

mr_ambivalence
Автор

i know that i know nothing :) but in few seconds i will know less nothing and eventaully i will know something. Thx once again !!

piotrkopcewicz
Автор

Dude, Bro Code is the only Human coder in the world that can explain something complex and simplify it.

Brimstoned_
Автор

Thank you, I really like your methods in presenting a concept.
I do have a comment on this video:
But even without this code: if name == main, import (file_name) will be enough to run every code in the imported file.
What I mean is that if name main is not essential to access codes from another file. It is also not essential to run a program.
I would like to see a program that absolutely cannot work without if name main command.

randalfaris
Автор

bro this video is like, so underrated

alastor
Автор

so basically, its just used during importing modules right?

vennjylugo
Автор

what if the name of the module is __main__?
then __main__.__name__ would be __main__ even if it is imported isn't it ?
btw would the name __main__ be accepted as a valid name?

arkamukhopadhyay
Автор

So basically its only __main__ within of itself

thegreatestpotato
Автор

Mine doesn't work the same 7/22/2022. I wonder if the pycharm software version was updated to work differently.

FushigiMigi
Автор

Sorry cause this is unrelated to the content of this video. But how do you trim off all the zeros in a printf statement. So for example I have 43.33 as a double and listed as %f.2 but it shows as in the command prompt. How do I fix it. Thanks in advance

AnMystery
Автор

Yo, what IDE is that? It looks really similar to android studio

AnthonyR