a = 15# int b = 2# int print('a + b = ', a+b) # int print('a - b = ', a-b) # int print('a * b = ', a*b) # int print('a / b = ', a/b) # float print('a // b = ', a//b) # int print('a % b = ', a%b) # int print('a ** b = ', a**b) # int
a + b = 17
a - b = 13
a * b = 30
a / b = 7.5
a // b = 7
a % b = 1
a ** b = 225
실수형 사칙연산
1 2 3 4 5 6 7 8 9
a = 15.0# float b = 2.0# float print('a + b =', a+b) # float print('a - b =', a-b) # float print('a * b =', a*b) # float print('a / b =', a/b) # float print('a // b =', a//b) # float print('a % b =', a%b) # float print('a ** b =', a**b) # float
a + b = 17.0
a - b = 13.0
a * b = 30.0
a / b = 7.5
a // b = 7.0
a % b = 1.0
a ** b = 225.0
논리형 연산자
Bool형은 True와 False 값으로 정의
AND, OR, NOT
1 2 3 4 5 6 7 8 9 10 11 12
x = 5 > 4 print('x =', x) y = 3 > 9 print('y =', y) print('x and x =', x and x) print('x and y =', x and y) print('y and x =', y and x) print('y and y =', y and y) print('x or x =', x or x) print('x or y =', x or y) print('y or x =', y or x) print('y or y =', y or y)
x = True
y = False
x and x = True
x and y = False
y and x = False
y and y = False
x or x = True
x or y = True
y or x = True
y or y = False
비교 연산자
부등호를 의미
비교 연산자를 True와 False 값을 도출
논리 & 비교 연산자 응용
1 2 3
var = input("숫자를 입력하시오. :") print(var) print(type(var))
숫자를 입력하시오. :24
24
<class 'str'>
1 2 3
var = int(input("숫자를 입력하시오. :")) print(var) print(type(var))
num = 8 day = 3 print("I ate {0} apples.".format(num)) print("I ate {0} apples, so I was sick for {1} days.".format(num, day))
print("I ate {num} apples, so I was sick for {day} days.".format(num=6,day=2)) print("I ate {0} apples, so I was sick for {day} days.".format(4,day=1))
I eat 7 apples.
I eat five apples.
I ate 8 apples.
I ate 8 apples, so I was sick for 3 days.
I ate 6 apples, so I was sick for 2 days.
I ate 4 apples, so I was sick for 1 days.