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

  • @fireemblem2770
    @fireemblem27703 жыл бұрын

    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

    @aykira7

    2 жыл бұрын

    same

  • @adrianarreguin1739
    @adrianarreguin1739 Жыл бұрын

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

  • @jag7450
    @jag7450 Жыл бұрын

    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.

  • @BroCodez
    @BroCodez3 жыл бұрын

    # *********************************** # 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() # ***********************************

  • @SuperSquall42
    @SuperSquall423 ай бұрын

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

  • @universalponcho
    @universalponcho2 жыл бұрын

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

  • @SergioSanchez-zw6mv
    @SergioSanchez-zw6mv Жыл бұрын

    Thanks a lot for this video!

  • @AlokTP
    @AlokTP4 ай бұрын

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

  • @mr_ambivalence
    @mr_ambivalence3 жыл бұрын

    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

  • @tanuj05
    @tanuj059 ай бұрын

    So good !

  • @SuperStarEevee
    @SuperStarEevee2 жыл бұрын

    Thank you!

  • @cristiucvladimir7909
    @cristiucvladimir79093 ай бұрын

    Thanks man!

  • @shavindasilva
    @shavindasilva2 жыл бұрын

    thank you bro

  • @piotrkopcewicz5227
    @piotrkopcewicz5227 Жыл бұрын

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

  • @beingzero7541
    @beingzero75412 жыл бұрын

    Wow!

  • @imanhosseini6908
    @imanhosseini6908 Жыл бұрын

    Organic Chem Tutor of Python

  • @wet_owl_
    @wet_owl_4 ай бұрын

    ty man

  • @bekturasanbekov1979
    @bekturasanbekov1979 Жыл бұрын

    thx 4 vid bro !

  • @uuhju7004
    @uuhju70043 жыл бұрын

    ty bro

  • @alastor1419
    @alastor14192 жыл бұрын

    bro this video is like, so underrated

  • @randalfaris1430
    @randalfaris14309 ай бұрын

    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.

  • @Brimstoned_
    @Brimstoned_7 ай бұрын

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

  • @gg-ci5gb
    @gg-ci5gb11 ай бұрын

    thanks chad This helped a lot

  • @letsflyhigh6883
    @letsflyhigh68833 жыл бұрын

    I'm understanding more now xD

  • @imanhosseini6908
    @imanhosseini6908 Жыл бұрын

    double like

  • @tomaszkarolak6179
    @tomaszkarolak61793 жыл бұрын

    Thx Bro!!!

  • @vamsidoddigunta2657

    @vamsidoddigunta2657

    Жыл бұрын

    Hi

  • @arkamukhopadhyay2177
    @arkamukhopadhyay21773 жыл бұрын

    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?

  • @thegreatestpotato6460
    @thegreatestpotato64603 жыл бұрын

    So basically its only __main__ within of itself

  • @FushigiMigi
    @FushigiMigi2 жыл бұрын

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

  • @majorgeneral2812
    @majorgeneral2812 Жыл бұрын

    You make it easy to understand budda.

  • @paantur
    @paantur Жыл бұрын

  • @vennjylugo7434
    @vennjylugo74342 жыл бұрын

    so basically, its just used during importing modules right?

  • @oximas-oe9vf

    @oximas-oe9vf

    2 жыл бұрын

    yep

  • @A4n27Mystery
    @A4n27Mystery3 жыл бұрын

    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

    @taijenseng

    3 жыл бұрын

    Here you go

  • @abdallahbadr4335

    @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

  • @hahaupscalinh7872
    @hahaupscalinh78725 ай бұрын

    Wtf?? entendi foi nada kkk

  • @AnthonyR007
    @AnthonyR0073 жыл бұрын

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

  • @thecodfather7109

    @thecodfather7109

    3 жыл бұрын

    Sublime I think

  • @notinuserightnoworever

    @notinuserightnoworever

    3 жыл бұрын

    PyCharm

  • @Jxrdy

    @Jxrdy

    3 жыл бұрын

    @The Codfather YOOOOOOOOOOOOOOOOO 😀👍😀😀

  • @mujtabahussain7015

    @mujtabahussain7015

    2 жыл бұрын

    @@thecodfather7109 bruhhhh

  • @jhassee
    @jhassee Жыл бұрын

    boobookittyfaq

Келесі