Comparison operator How to use Description
A> B Is A greater than B? = A> = B Is A more than B? <A <B A is less than B <= A <= B Is A less than or equal to B? == A == B Are A and B equal?
true, false
python
#Is 1 less than 20?
irb(main):001:0> 1 < 20
=> true
#Is 5 less than 5?
irb(main):002:0> 5 <= 5
=> true
#Is 1 greater than 20?
irb(main):003:0> 1 > 20
=> false
#Is 5 more than 5?
irb(main):004:0> 5 >= 5
=> true
#Is 2 x 5 equal to 10?
irb(main):005:0> 2 * 5 == 10
=> true
#Is 10 equal to 20?
irb(main):006:0> 10 == 20
=> false
python
#Isn't 2 x 3 6?
irb(main):001:0> 2 * 3 != 6
=> false
#Isn't 2 x 3 10?
irb(main):002:0> 2 * 3 != 10
=> true
python
if conditional expression
processing
end
python
if conditional expression
#Conditional expression is true(true)Processing to be executed at
else
#Conditional expression is false(false)Processing to be executed at
end
python
if conditional expression 1
#Conditional expression 1 is true(true)Processing to be executed at
elsif conditional expression 2
#Conditional expression 1 is false(false)At that time
#Conditional expression 2 is true(true)Processing to be executed at
else
#Both conditional expression 1 and conditional expression 2 are false(false)Processing to be executed at
end
Recommended Posts