Python if __name__ == '__main__' ❓
Ғылым және технология
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 👟 :
===========================================================
teespring.com/stores/bro-code-5
===========================================================
Пікірлер: 46
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!!
@aykira7
2 жыл бұрын
same
Dude! Thank you! I was so confused in my textbook. Always come to your channel to understand.
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.
# *********************************** # 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() # ***********************************
You explained this so much clearer than the other videos I watched. Thank you!
I've missed watching your videos. I am so happy that I have a reason to again
Thanks a lot for this video!
Thank you. I never ever was able to understand this topic so clearly till now.
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
So good !
Thank you!
Thanks man!
thank you bro
i know that i know nothing :) but in few seconds i will know less nothing and eventaully i will know something. Thx once again !!
Wow!
Organic Chem Tutor of Python
ty man
thx 4 vid bro !
ty bro
bro this video is like, so underrated
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.
Dude, Bro Code is the only Human coder in the world that can explain something complex and simplify it.
thanks chad This helped a lot
I'm understanding more now xD
double like
Thx Bro!!!
@vamsidoddigunta2657
Жыл бұрын
Hi
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?
So basically its only __main__ within of itself
Mine doesn't work the same 7/22/2022. I wonder if the pycharm software version was updated to work differently.
You make it easy to understand budda.
so basically, its just used during importing modules right?
@oximas-oe9vf
2 жыл бұрын
yep
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 43.3300000 in the command prompt. How do I fix it. Thanks in advance
@taijenseng
3 жыл бұрын
Here you go
@abdallahbadr4335
Жыл бұрын
too late but you can use the round function like that round(number, 2) the second argument is the number of digits after the decimal point
Wtf?? entendi foi nada kkk
Yo, what IDE is that? It looks really similar to android studio
@thecodfather7109
3 жыл бұрын
Sublime I think
@notinuserightnoworever
3 жыл бұрын
PyCharm
@Jxrdy
3 жыл бұрын
@The Codfather YOOOOOOOOOOOOOOOOO 😀👍😀😀
@mujtabahussain7015
2 жыл бұрын
@@thecodfather7109 bruhhhh
boobookittyfaq