1797/python-switch-construct
You can use the python dictionary for this purpose:
def switch(x): return { 'a': 1, 'b': 2 }.get(x, 10) # 10 is default if x not found
...
switch('b')
Check out the docs for the dict.get() here: https://docs.python.org/3.6/library/stdtypes.html#dict.get
You could use a dictionary: def f(x): ...READ MORE
if x == 'a': # Do the ...READ MORE
The recommended path for Python 3.10 which ...READ MORE
You can index into a tuple: (falseValue, trueValue)[test] test needs ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can simply the built-in function in ...READ MORE
Yes, the syntax is: a if condition else ...READ MORE
Use the "in" operator in python" if "substring" ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.