주간 퀴즈를 풀면서 궁금한 내용을 찾아봤다.
data1 = '10'
data2 = "10"
print(bool(data1) + bool(data2))
>>>
2
⭐https://docs.python.org/3/library/stdtypes.html#boolean-type-bool
bool is a subclass of int (see Numeric Types — int, float, complex). In many numeric contexts, False and True behave like the integers 0 and 1, respectively. However, relying on this is discouraged; explicitly convert using int() instead.
number = 10.9132865
print('number = %.4f' % number)
>>>
number = 10.9133
⭐https://docs.python.org/3/library/stdtypes.html#old-string-formatting
# int() - 버림
print(int(1.4))
print(int(1.5))
# math.trunc() - 버림
# truncated == '잘린'
print(math.trunc(1.4))
print(math.trunc(1.5))
# math.ceil() - 올림
print(math.ceil(1.4))
print(math.ceil(1.5))
# math.floor() - 내림
print(math.floor(1.4))
print(math.floor(1.5))
# round() - 반올림
print(round(1.4)) # 1
print(round(1.6)) # 2
## 반올림할 숫자가 5일 때, 앞자리 숫자가 홀수면 올리고 짝수면 내림
print(round(1.5)) # 2
print(round(2.5)) # 2
print(round(3.5)) # 4
print(round(4.5)) # 4