Python gets REAL Switch Case Statement

preview_player
Показать описание
Python Switch Case Tutorial - It's happening! We're getting a pattern match feature like a switch case statement in Python3.10. Here is what you need to know and how you can try and test out the Alpha Version of Python3.10 yourself. #Python #Python3 #HomeLab

Follow me:

Timestamps:

00:00 - Introduction
00:32 - What's happening?
02:10 - How to test match in Python3.10 Alpha

----
All links with "*" are affiliate links.
Рекомендации по теме
Комментарии
Автор

Well currently you can also get the "illusion" of a switch case statement in python by using a function and dictionary.

AnimeRPG
Автор

Just learned about this new feature in the Python 3.10 official release docs and was curious about how to use it (Python is my first language); this is very informative, thank you! Also exciting that the new version is out officially

thatsnare
Автор

me googling how to do a switch statement in python.. realizing the most demanded language (to learn) doesn't have it.. guys...?

marcello
Автор

This is hardly a "switch:case" statement. The purpose of "switch:case" is speed of comparison and quick terminations. The issue with if/then, is simply horrible speed of checking each individual comparison with a "wide set match", which is exactly what the match:case is doing. They just hid the if/then tree and added an auto-terminate to them. So, it not only fails to work like EVERY switch:case in history... (including speed and function)... It is, at the core, still just a horrible, specific case use with no functional gains, might be right or not, hack.

The best solution is still to make your own with a simple DICT and a function. At-least it functions MORE like an actual switch:case, with literal comparisons, not close-enough-to-be-wrong comparisons. (Comparisons which might also NEED more coding to add MORE checking, since it is not "switching" to the next, to see if there is ALSO a match. Now you are back to nested loops and horrible matching, making it 10x worse than if:then statements.)

The current developers need to STOP developing and let the actual PROGRAMMERS determine what the PROGRAMMERS need in Python. As opposed to dictating what the programmers can have, because, "reasons"...

JD_Mortal
Автор

Switch Case in python is much more than covered in this video.

alexanderkorshkov
Автор

btw how did you get zsh working on your wsl?

syumak
Автор

I've have Switch in Python 2.5. So, someone has had to have written one for Python 3.x.

SHONNER
Автор

I think comparing this new feature to switch statements is strongly underselling it.
Besides just matching primitives, you can also use it to match class instances, dictionaries, lists, subfields of all of these and you can even extract partial data

Topfpflanze
Автор

When teachers show switch-case, the next thing they teach is that you should forget it. In my opinion, switch-case is more fragile and harder to debug than if-else, and it has got nothing to do with elegant way of coding, not to mention nested switch-case, which is nothing but nonsense.

SomKonor
Автор

How is this still not avaliable? I tried the same "match string" code on Pycharm and it is not recognising it :((((

cyrusking
Автор

I'm planning to learn Python, i know java, why case statement wasn't in python

PetritK
Автор

I always thought why the heck do we need break when we have specific cases for each command, no wonder python is used for AI, python is very smart, thank you for this tutorial hoping to see more

shreehari