Python supports the usual logical conditions from mathematics:
- Equals: a==b
- Not Equals: a!=b
- Less than: a<b
- Less than or equal to: a<=b
- Greater than: a>b
- Greater than or equal to: a>=b
These conditions can be used in several ways, most commonly in "if statements" and loops.
Code Examples😁:
(출력값은 주석으로 표시)
a=200;
b=33;
if b>a:
print("b is greater than a");
elif a==b:
print("a and b are equal.");
else:
print("a is greater than b."); #a is greater than b
x=[1,2,3];
y=(1,2,3);
if len(x)==len(y):print("same length"); #same length
else:print("different length");
a=2;
b=330;
print("a") if a>b else print("b"); #b
a=220;
b=220;
print("a") if a>b else print("=") if a==b else print("b") #=
#elif는 쓸 수 없다.
'Python🍍' 카테고리의 다른 글
Python Lambda🍋 (0) | 2022.06.27 |
---|---|
Python Function✨ (0) | 2022.06.27 |
Python 반복문 while, for⚡ (0) | 2022.06.27 |
Python Operators👀 (0) | 2022.06.25 |
Python Data Types💥 (0) | 2022.06.25 |