TIL[29]. Python_Comparison Operators

jake.log·2020년 8월 22일
0

Python

목록 보기
11/39

11.Comparison Operators

== 는 equality operator 라고 한다.
이는 comparison operator 들 중 하나다.
즉 2개의 값들을 비교할때 쓰이는 operator 이다.

comparison operator 들에는 == 외에도 다양한 operator들이 있다.

01. != operator

"Not Equal to" 이며 == operator와 반대의 의미를 가지고 있다.
즉 2개의 값이 서로 불일치 하는지 비교하는 역할을 한다.

if name != "jake":
    print("jake가 아닙니다..")

if age != 30:
    print("30살이 아닙니다.")

02. > operator

>은 "Greater than" 이며 어떠한 값이 다른 값보다 더 큰지를 비교할 때 사용되는 operator다.

if age > 40:
    print("아직 젊습니다.")

if character > "b":
    print("c 혹은 그 다음 알파벳들중 하나 이겠군요?")

숫자 뿐만이 아니라 string도 > 으로 비교할 수 있다.

03.< operator

< 은 "less than" 이며 > 의 반대 의미.
어떠한 값이 다른 값보다 더 작은지를 비교할 때 사용된다.

if age < 30:
    print("부럽다..")

if character < "b":
    print("b 보다 작으면 a 이겠네요.")

04.>= operator

>= 는 greater than or equal to 이며 어떠한 값이 다른 값 보다 크거나 혹은 같은지 를 비교할 때 사용된다.

if height >= 180:
    print("키가 180 이상이시군요.")

05.<= operator

<= 는 less than or equal to 이며 어떠한 값이 다른 값 보다 작거나 혹은 같은지 를 비교할 때 사용된다.

if price <= 20000:
    print("2만원 이하 이면 괜찮다.")

Assignment

만일 input 값이 3자리 수 이상의 수 이면 "YES" 를 출력하시고 아니면 "NO" 를 출력하세요.
Input 값은 자동으로 입력됩니다.

My solution

number = int(input())

def solution():
    if number > 99:
        print("YES")
    else :
        print("NO")

Model solution

number = int(input())

if number >= 100:
  print("YES")
 
if number < 100:
  print("NO")
profile
꾸준히!

0개의 댓글