Python Syntax
APS ๊ณต๋ถํ๋ค๊ฐ ๊ทธ ๋ ๊ทธ ๋ ํ์ํ ๋ฌธ๋ฒ๋ค ์ ๋ฆฌ
์ดํ์ Syntax ์ฃผํผํฐ ๋ ธํธ๋ถ๋ค์ ๋ชจ๋ ์๋ ( ์๋ง ๊ฑฐ์ ? ) ๋ด์ฉ์ด๊ธด ํจ
์์์ ํ๊ธฐ
a=float(input()) print("{:.6f}".format(a))
๋ค์ง๊ธฐ
a=[1,2,3] a.reverse() print(a) => [3,2,1]
iterable ์ ํน์ ํ ๋ฌธ์์ด๋ก ๋ง๋ค๊ธฐ
print('!'.join(word)) ###join ์์ ์ฐ๊ฒฐ๊ณ ๋ฆฌ๋ฅผ ๊ธฐ์ ํด์ค print(' '.join(word))
.์ผ๋ก ๋๋ ์ธํ ๋ฐ๊ณ , ์ํ๋ ๋งํผ ๊ณต๋ฐฑ๋ฃ๊ธฐ ( https://dojang.io/mod/page/view.php?id=2300 )
a,b,c = input().split('.') print("{:0>4}.{:0>2}.{:0>2}".format(a,b,c))
์ง์
value = 60 b = bin(value) = "0b~" o = oct(value) = "0o~" h = hex(value) = "0x~" b = "{:#b}".format(value) o = "{:#o}".format(value) h = "{:#h}".format(value) value = int("0o13",8) = 11 value = int("0b11",2) = 3 value = int("0xf",16) = 15
ํน์ ํ ๋ฌธ์ ์ ๊ฑฐํ๊ธฐ
a = oct(int(input()) # a = '0o12' print(a.lstrip('0o')
์์คํค ์ฝ๋
print(chr(45)) print(ord("A"))
๋นํธ์ฐ์ฐ
๋นํธ ์ฐ์ฐ์ (Bitwise Operators): a = 60, b = 13 ์ด๋ผ ๊ฐ์ ํ๋ค. a = 0011 1100 b = 0000 1101 Operator Description Example & AND ์ฐ์ฐ. ๋๋ค ์ฐธ์ผ๋๋ง ๋ง์กฑ (a & b) = 12 โ 0000 1100 | OR ์ฐ์ฐ. ๋ ์ค ํ๋๋ง ์ฐธ์ด์ฌ๋ ๋ง์กฑ (a | b) = 61 โ 0011 1101 ^ XOR ์ฐ์ฐ. ๋ ์ค ํ๋๋ง ์ฐธ์ผ ๋ ๋ง์กฑ (a ^ b) = 49 โ 0011 0001 ~ ๋ณด์ ์ฐ์ฐ. (~a) = -61 โ 1100 0011 << ์ผ์ชฝ ์ํํธ ์ฐ์ฐ์. ๋ณ์์ ๊ฐ์ ์ผ์ชฝ์ผ๋ก ์ง์ ๋ ๋นํธ ์ ๋งํผ ์ด๋ a << 2 = 240 โ 1111 0000 >> ์ค๋ฅธ์ชฝ ์ํํธ ์ฐ์ฐ์. ๋ณ์์ ๊ฐ์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ง์ ๋ ๋นํธ ์ ๋งํผ ์ด๋ a >> 2 = 15 โ 0000 1111
๋ฆฌ์คํธ ์ปดํ๋ฆฌ ํจ์
array = [i for i in range(20) if i % 2 == 1 ] array = [i * i for i in range(1,10)]
๋ฆฌ์คํธ์์ ํน์ ๊ฐ์ ์์ ๋ชจ๋ ์ ๊ฑฐ
a = [1,2,3,4,5,5,5] remove_set = {3,5} result = [i for i in a if not in remove_set] print(result) [1,2,4]
Last updated
Was this helpful?