Now it is very simple to use Match/Case since well, Match is literally to match
the user’s input. Case is well, you create a case. If this case match
es the user input, then it executes the code thats after the case.
Here is an example
inp = input('Hey there, Testing Case and Match!')
match inp:
case '3': #Basically its. if this case matches <insert something here lolz >
print('Well, yeah. 3, thats about it.')
case '1':
print('Yeah. 1, probably not my fav number but okay?')
#Note, there is NO else in here.
side note: this is the default case:
case _:
<insert code to execute>
using match and case as an alternative for if statements is great. Since beginners can understand better about the alternatives for if statements. It can also save time when writing alot of ifs, elifs,etc. This can also make your code look neat and tidy, not some messy code. Heres the difference:
inp = inp = input('Hey there, Comparing some stuff!')
if inp == '3':
print('Yeah its just a test')
elif inp == '1':
print('Yeah, 1. But its just a test lolz')
Honestly, its just way more neat and it makes stuff easier since theres some errors you can make if you use if statements ( eg. inp = ‘1’ instead of inp == ‘1’ or inp == 1 instead of inp == ‘1’ )
Thats how you properly use Match/Case.
If you read all this, Thank you! And maybe you should go edit your code and put this in!