๋ฐ์ดํธ ์ฝ๋๋?
๋ฐ์ดํธ ์ฝ๋(Byte code)๋ ๊ณ ๊ธ ์ธ์ด๋ก ์์ฑ๋ ์์ค ์ฝ๋๋ฅผ ๊ฐ์๋จธ์ ์ด ์ดํดํ ์ ์๋ ์ค๊ฐ ์ฝ๋๋ก ์ปดํ์ผํ ๊ฒ์ ๋งํ๋ค.
์๋ ์ฝ๋๋ else์ elif ์ ์๊ฐ์ฐจ๋ฅผ ํ์ธํ๊ธฐ ์ํด dis ๋ชจ๋์ ์ฌ์ฉํจ.
import dis
def Func_else(n):
if n % 2 == 0:
return True
else:
return False
def Func_elif(n):
if n % 2 == 0:
return True
elif n % 2 == 1:
return False
dis.dis(Func_else)
print('--------------------------------------------------')
dis.dis(Func_elif)
๊ฒฐ๊ณผ:
4 0 LOAD_FAST 0 (n)
2 LOAD_CONST 1 (2)
4 BINARY_MODULO
6 LOAD_CONST 2 (0)
8 COMPARE_OP 2 (==)
10 POP_JUMP_IF_FALSE 8 (to 16)
5 12 LOAD_CONST 3 (True)
14 RETURN_VALUE
7 >> 16 LOAD_CONST 4 (False)
18 RETURN_VALUE
---------------------------------------------------------
10 0 LOAD_FAST 0 (n)
2 LOAD_CONST 1 (2)
4 BINARY_MODULO
6 LOAD_CONST 2 (0)
8 COMPARE_OP 2 (==)
10 POP_JUMP_IF_FALSE 8 (to 16)
11 12 LOAD_CONST 3 (True)
14 RETURN_VALUE
12 >> 16 LOAD_FAST 0 (n)
18 LOAD_CONST 1 (2)
20 BINARY_MODULO
22 LOAD_CONST 4 (1)
24 COMPARE_OP 2 (==)
26 POP_JUMP_IF_FALSE 16 (to 32)
13 28 LOAD_CONST 5 (False)
30 RETURN_VALUE
12 >> 32 LOAD_CONST 0 (None)
34 RETURN_VALUE
๊ฒฐ๋ก : ์๊ฐ ๋จ์ถ์ด ํ์ํ๋ค๋ฉด else๋ฅผ ์ธ ์ ์๋ ๊ฒฝ์ฐ์๋ else๋ฅผ ์ฐ์.
์ฐธ๊ณ
'๐ Language > [python]' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ์ด์ฌ] ์ฌ๋ฌ ํ์ผ ์ด๋ฆ ํ๋ฒ์ ๋ณ๊ฒฝํ๋ ํ๋ก๊ทธ๋จ ๋ง๋ค๊ธฐ(feat. os.rename) (0) | 2023.07.28 |
---|---|
[ํ์ด์ฌ] ์ฝฐ์ธ(Quine) ํ๋ก๊ทธ๋จ (0) | 2023.07.20 |
[ํ์ด์ฌ] ํ์ด์ฌ ์ฝ๋ ์คํ ์ธก์ - time (0) | 2022.08.05 |
[ํ์ด์ฌ] if __name__ == "__main__" (0) | 2022.08.03 |
[ํ์ด์ฌ] ์์ด๊ณผ ์กฐํฉ - permutations, combinations (0) | 2022.08.03 |