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=2300arrow-up-right )

    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