Python - Switch Statement is Finally Here (How To Use Case in Python)

preview_player
Показать описание
#Python #Shorts

In a lot of other programming languages we can use a switch statement to eliminate a bunch of if/else statements. They are less necessary in Python since it doesn't use brackets and there's not much space saving you can do. But they decided to add it anyways. Here's how it works.
You use the word "match" that is followed by something you want to match against. Then, you specify your "case" or multiple cases to determine what should happen when a match is found.
You can have an exact match, or you could use a pipe (|) to use as an "or".
Lastly, if a match is not found, you can either not do anything, or you can add a "wildcard" case using an underscore. If no other matches are found, the code in this block will be executed.
This will only be available with Python 3.10, so you may not see it, unless you download a developer build.
-------------------------------------------------------------------------------------
Links:
Рекомендации по теме
join shbcf.ru