15 Respuestas
+ 13
well, what can i replace it with?
+ 13
is there anything shorter than if... else?
+ 13
thank you visph
+ 13
yey thank you guys :)
+ 12
Can someone upvote this, so I can get a badge please?
+ 4
switch case is not available in python.... To simulate it you can use multiple if statements....
+ 2
switch statement is not available in Python
+ 2
if... else
+ 2
no
+ 2
switch-case is error prone. Nevertheless, in many languages, it can be used for limited types. I think that is why a solid practical language like Python does not bother to provide it. Use good old if-else, you can use it for any complex conditions as well as can use them within hierarchy.
- 1
# Gami in regard to alternatives to if else
# in python
import this
my_var = 55
my_var2 = 56
if my_var < my_var2:
print('smaller')
else:
print('equal or larger')
# there are other options
# to if else but they are not
# always as obvious to interpret.
# Consider that python's ethos is clarity
# if choosing to use them
print(('equal or larger','smaller')[my_var < my_var2])
- 1
this will give u the basic idea of how to use switch
- 1
use can use nested if-else or else if statement s
- 2
public class Program {
public static void main(String[] args) {
int day = 3;
switch(day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
}
}
}