How to Use Python Match Case Statements

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 มิ.ย. 2023
  • A 'match case' statement in Python allows you to check a variable or function value and perform different things based on the result!
    It is a good replacement for applications that use a lot of repetitive if-else statements and is similar to match case syntax of other C-based programming languages!
    Feel free to leave a comment with any questions or to say what you'd like to see on the channel next, and don't forget to leave a like on the video and subscribe to the channell!
    Thanks for watching and goodluck with your code!
    Check out my Patreon if you'd like to become a super supporter of the channel! / lemastertech
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @flioink
    @flioink ปีที่แล้ว +7

    Looks to be a more advanced version of the "switch" statement from the C languages.
    Wonder why it took them so long to add it in but I'm glad it's available - much more intuitive.

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

      Agreed! That was my first impression too and I sometimes forget to use it because I’ve gotten so used to the if elif chains but it’s a nice hack for sure 😎

  • @kylemuldrow4652
    @kylemuldrow4652 6 หลายเดือนก่อน +2

    Very well done tutorial! Did you say, however, that this is only available in Python 3.10 or later? I just upgraded to Python 3.12, so wanting to make sure I can use it.

    • @lemastertech
      @lemastertech  6 หลายเดือนก่อน

      Hello and thank you! Yes according to pythons official release notes this is a new feature as of python 3.10!! And it is available in all versions going forward now :)

  • @SUCCESS_GUY
    @SUCCESS_GUY 2 วันที่ผ่านมา +1

    Can we use match case statement for matching a string in python , I am struggling with this in python ❤.

    • @lemastertech
      @lemastertech  14 ชั่วโมงที่ผ่านมา

      Hi it is not really meant for that it’s really for numerical comparison, there are other efficient ways to check for string matching!

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

    Haha, the thing is, I was wondering how to do this and you made a tutorial on it. Now that is luck.🎮

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

      Very cool!! Glad it could be helpful! :)

  • @Shankar9209
    @Shankar9209 10 หลายเดือนก่อน +1

    Thanks forms india❤

    • @lemastertech
      @lemastertech  10 หลายเดือนก่อน +1

      You’re very welcome!! Thanks for watching

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

    how about something like this
    switch (DrawingMode)
    {
    case Drawing.TurtleSnowflake:
    drawable = new TurtleSnowflake();
    break;
    case Drawing.TurtleGosper:
    drawable = new TurtleGosper();
    break;

    • @lemastertech
      @lemastertech  หลายเดือนก่อน +2

      Hi, all I have seen the case switching for in Python is off of numerical values - this looks like you want to switch off a variables status so I would suggest actually just using if else if statements for this one!!

  • @terrificgadgets2770
    @terrificgadgets2770 23 วันที่ผ่านมา +1

    Thanks from Pakistan

    • @lemastertech
      @lemastertech  22 วันที่ผ่านมา

      You’re welcome thanks for watching!!