--The ternary operator is written in different languages.
Python
score = 100
result = ""
if score >= 60:
result = "Pass"
else:
result = "failure"
print(result)
--Ternary operator
score = 100
result = "Pass" if score >= 60 else "不Pass"
print(result)
Java
Integer score = 100;
String result = "";
if(score>=60){
result = "Pass";
}else{
result = "failure";
}
System.out.println(result);
--Ternary operator
Integer score = 100;
String result = (score >= 60)?"Pass":"不Pass";
System.out.println(result);
C
int score = 100;
char *result;
if(score >= 60){
result = "Pass";
}else{
result = "failure";
}
printf("%s",result);
--Ternary operator
int score = 100;
char *result = (score >= 60) ? "Pass":"不Pass";
printf("%s",result);
C#
int score = 100;
string result = "";
if(score>=60){
result = "Pass";
}else{
result = "failure";
}
System.Console.WriteLine(result);
--Ternary operator
int score = 100;
string result = (score >= 60)?"Pass":"不Pass";
System.Console.WriteLine(result);
Recommended Posts