๋ฐ์ํ
โ๏ธint ํ์ ์ ๋ฌดํ๋
sys.maxsize
python3์์ int์ ์ต๋๊ฐ์ sys๋ฅผ importํ ๋ค์ maxsize๋ฅผ ๊ตฌํด๋ณด๋ฉด ์ ์ ์๋ค.
import sys
test = sys.maxsize
print(test)
list1 = range(test)
print(len(list1))
"""
<๊ฒฐ๊ณผ>
2147483647
2147483647
"""
python3์ด์์์ intํ์ ์ด๊ณผํ ๊ฒฝ์ฐ ์๋์ผ๋ก long์ผ๋ก ๋ณํ๋๊ธฐ ๋๋ฌธ์
๋ค์๊ณผ ๊ฐ์ ์ฐ์ฐ๋ ๊ฐ๋ฅํ๋ค.
# ์ต๋ ์ ์๊ฐ ์ด๊ณผ์ long์ผ๋ก ์๋ ๋ณํ
test += 1
print(test)
"""
<๊ฒฐ๊ณผ>
2147483648
๋ฐ๋ฉด int์ ์ต๋๊ฐ์ ์ด๊ณผํ๊ฒ ๋๋ฉด list๋ฅผ ์์ฑ ํ ์ ์๋ค.
list2 = range(test)
print(len(list2))
"""
<์๋ฌ ๋ฉ์์ง>
OverflowError: Python int too large to convert to C ssize_t
"""
โ๏ธfloat ํ์ ์ ๋ฌดํ๋
float ํ์ ์ ๋ฌดํ๋๋ฅผ ํ์ํ๋ ๋ฐฉ๋ฒ์ ๋ ๊ฐ์ง๊ฐ ์กด์ฌํฉ๋๋ค.
1) math ๋ชจ๋ ์ฌ์ฉ
import math
max_float = math.inf
min_float = -math.inf
# inf
# -inf
2) float ๋ด์ฅํจ์ ์ฌ์ฉ
max_float = float('inf')
min_float = float('-inf')
min_float2 = -float('inf')
# inf
# -inf
# -inf
math ๋ชจ๋์ ์ฌ์ฉํ๊ฑฐ๋ float ๋ด์ฅํจ์๋ฅผ ์ฌ์ฉํด์ ๋์จ ๊ฒฐ๊ณผ๊ฐ์ ๋ชจ๋ ๋์ผํฉ๋๋ค.
import math
max_math_float = math.inf
max_float = float('inf')
# True๋ฐ์ํ
'Algorithm๐ค > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [์๋ฃ๊ตฌ์กฐ๐ฑ] ๋์ ๋๋ฆฌ (0) | 2023.06.07 |
|---|---|
| [Python๐ฑ] ๋ฌธ์์ด ๋น๊ต ์์ ์ผ์น ๋ถ๋ถ ์ผ์น (0) | 2023.06.07 |
| [์ฝํ ๋ฌธ๋ฒ] split ๋ฆฌ์คํธ ๐ ๋ฌธ์์ด (0) | 2023.06.01 |
| [์ฝํ ๋ฌธ๋ฒ] Join ๋ฆฌ์คํธ ๐ ๋ฌธ์์ด (0) | 2023.06.01 |
| [Python] 2์ฐจ์ list(ํ, ์ด, ํ) (0) | 2023.05.21 |