Python if __name__ == '__main__' ❓

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ธ.ค. 2024

ความคิดเห็น • 47

  • @fireemblem2770
    @fireemblem2770 3 ปีที่แล้ว +45

    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 3 ปีที่แล้ว

      same

  • @BroCodez
    @BroCodez  3 ปีที่แล้ว +11

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

  • @jag7450
    @jag7450 ปีที่แล้ว +5

    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.

  • @SuperSquall42
    @SuperSquall42 8 หลายเดือนก่อน

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

  • @adrianarreguin1739
    @adrianarreguin1739 ปีที่แล้ว +2

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

  • @AlokTP
    @AlokTP 8 หลายเดือนก่อน

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

  • @universalponcho
    @universalponcho 2 ปีที่แล้ว +1

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

  • @mr_ambivalence
    @mr_ambivalence 3 ปีที่แล้ว +8

    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

  • @imanhosseini6908
    @imanhosseini6908 2 ปีที่แล้ว +1

    Organic Chem Tutor of Python

  • @piotrkopcewicz5227
    @piotrkopcewicz5227 2 ปีที่แล้ว +1

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

  • @tanuj05
    @tanuj05 ปีที่แล้ว

    So good !

  • @Brimstoned_
    @Brimstoned_ 11 หลายเดือนก่อน

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

  • @SergioSanchez-zw6mv
    @SergioSanchez-zw6mv 2 ปีที่แล้ว

    Thanks a lot for this video!

  • @beingzero7541
    @beingzero7541 2 ปีที่แล้ว

    Wow!

  • @bekturasanbekov1979
    @bekturasanbekov1979 ปีที่แล้ว

    thx 4 vid bro !

  • @alastor1419
    @alastor1419 2 ปีที่แล้ว

    bro this video is like, so underrated

  • @imanhosseini6908
    @imanhosseini6908 2 ปีที่แล้ว

    double like

  • @shavindasilva
    @shavindasilva 2 ปีที่แล้ว

    thank you bro

  • @SuperStarEevee
    @SuperStarEevee 2 ปีที่แล้ว

    Thank you!

  • @gg-ci5gb
    @gg-ci5gb ปีที่แล้ว

    thanks chad This helped a lot

  • @arkamukhopadhyay2177
    @arkamukhopadhyay2177 3 ปีที่แล้ว +4

    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?

  • @randalfaris1430
    @randalfaris1430 ปีที่แล้ว

    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.

  • @cristiucvladimir7909
    @cristiucvladimir7909 7 หลายเดือนก่อน

    Thanks man!

  • @tomaszkarolak6179
    @tomaszkarolak6179 3 ปีที่แล้ว +1

    Thx Bro!!!

  • @uuhju7004
    @uuhju7004 3 ปีที่แล้ว

    ty bro

  • @vennjylugo7434
    @vennjylugo7434 3 ปีที่แล้ว +11

    so basically, its just used during importing modules right?

  • @wet_owl_
    @wet_owl_ 9 หลายเดือนก่อน

    ty man

  • @majorgeneral2812
    @majorgeneral2812 ปีที่แล้ว

    You make it easy to understand budda.

  • @letsflyhigh6883
    @letsflyhigh6883 3 ปีที่แล้ว

    I'm understanding more now xD

  • @paantur
    @paantur 2 ปีที่แล้ว

  • @FushigiMigi
    @FushigiMigi 2 ปีที่แล้ว

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

  • @thegreatestpotato6460
    @thegreatestpotato6460 3 ปีที่แล้ว +2

    So basically its only __main__ within of itself

  • @A4n27Mystery
    @A4n27Mystery 3 ปีที่แล้ว

    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 2 ปีที่แล้ว

      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

  • @AnthonyR007
    @AnthonyR007 3 ปีที่แล้ว

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

  • @hahaupscalinh7872
    @hahaupscalinh7872 9 หลายเดือนก่อน +1

    Wtf?? entendi foi nada kkk

  • @jhassee
    @jhassee 2 ปีที่แล้ว

    boobookittyfaq