λ°˜μ‘ν˜•

🎈 λ‚΄μž₯ν•¨μˆ˜

νŒŒμ΄μ¬μ—λŠ” 기본적으둜 μ œκ³΅λ˜λŠ” λ‚΄μž₯ ν•¨μˆ˜λ“€μ΄ μžˆμ–΄ λ³„λ„μ˜ μ„€μΉ˜ 없이 μ‚¬μš©ν•  수 μžˆλ‹€. λ‚΄μž₯ ν•¨μˆ˜λŠ” 데이터 처리, μž…λ ₯/좜λ ₯, μˆ˜ν•™ 계산 λ“± λ‹€μ–‘ν•œ μž‘μ—…μ„ μ‰½κ²Œ μˆ˜ν–‰ν•  수 있게 ν•œλ‹€.

 

 

- abs(): 숫자의 μ ˆλŒ€κ°’μ„ λ°˜ν•˜λŠ” ν•¨μˆ˜.

    print(abs(-5)) # 좜λ ₯: 5

 

- all(): 반볡 κ°€λŠ₯ν•œ 객체(리슀트, νŠœν”Œ λ“±) μ•ˆμ˜ λͺ¨λ“  값이 참이면 Trueλ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

    print(all([True, 1, "hello"])) # 좜λ ₯: True

 

- any(): 반볡 κ°€λŠ₯ν•œ 객체 μ•ˆμ˜ κ°’ 쀑 ν•˜λ‚˜λΌλ„ 참이면 Trueλ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

    print(any([False, 0, None, "text"])) # 좜λ ₯: True

 

- chr(): μœ λ‹ˆμ½”λ“œ 값을 문자둜 λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(chr(65))  # 좜λ ₯: 'A'

 

- ord(): 문자의 μœ λ‹ˆμ½”λ“œ 값을 λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(ord('A'))  # 좜λ ₯: 65

 

- divmod(): 두 수λ₯Ό λ‚˜λˆˆ λͺ«κ³Ό λ‚˜λ¨Έμ§€λ₯Ό νŠœν”Œλ‘œ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(divmod(10, 3))  # 좜λ ₯: (3, 1)

 

- enumerate(): 반볡 κ°€λŠ₯ν•œ 객체(리슀트 λ“±)μ—μ„œ μΈλ±μŠ€μ™€ 값을 ν•¨κ»˜ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  fruits = ['apple', 'banana']
  for index, fruit in enumerate(fruits):
      print(index, fruit)
  # 좜λ ₯:
  # 0 apple
  # 1 banana

 

- eval(): λ¬Έμžμ—΄ ν˜•νƒœμ˜ ν‘œν˜„μ‹μ„ μ‹€ν–‰ν•˜λŠ” ν•¨μˆ˜.

  print(eval("3 + 5"))  # 좜λ ₯: 8

 

- filter(): ν•¨μˆ˜μ˜ 쑰건을 λ§Œμ‘±ν•˜λŠ” μš”μ†Œλ§Œ κ±ΈλŸ¬λ‚΄λŠ” ν•¨μˆ˜.

  numbers = [1, 2, 3, 4, 5]
  even_numbers = list(filter(lambda x: x % 2 == 0, numbers))
  print(even_numbers)  # 좜λ ₯: [2, 4]

 

- hex(): μ •μˆ˜λ₯Ό 16μ§„μˆ˜ λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(hex(255))  # 좜λ ₯: '0xff'

 

- id(): 객체의 κ³ μœ ν•œ ID 값을 λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  a = 3
  print(id(a))  # 좜λ ₯: λ©”λͺ¨λ¦¬ μ£Όμ†Œκ°’ (예: 140722945015568)

 

- int(): λ¬Έμžμ—΄μ΄λ‚˜ μ‹€μˆ˜λ₯Ό μ •μˆ˜λ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(int("10"))  # 좜λ ₯: 10
  print(int(3.14))  # 좜λ ₯: 3

 

- isinstance(): μΈμŠ€ν„΄μŠ€κ°€ νŠΉμ • 클래슀의 μΈμŠ€ν„΄μŠ€μΈμ§€ ν™•μΈν•˜λŠ” ν•¨μˆ˜.

  print(isinstance(5, int))  # 좜λ ₯: True

 

- len(): 객체(λ¬Έμžμ—΄, 리슀트 λ“±)의 길이λ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(len("hello"))  # 좜λ ₯: 5

 

- list(): 반볡 κ°€λŠ₯ν•œ 객체λ₯Ό 리슀트둜 λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(list("hello"))  # 좜λ ₯: ['h', 'e', 'l', 'l', 'o']

 

- map(): 리슀트 λ“±μ˜ 각 μš”μ†Œμ— ν•¨μˆ˜λ₯Ό μ μš©ν•˜λŠ” ν•¨μˆ˜.

  numbers = [1, 2, 3]
  print(list(map(str, numbers)))  # 좜λ ₯: ['1', '2', '3']

 

- max(): 반볡 κ°€λŠ₯ν•œ 객체의 μ΅œλŒ“κ°’μ„ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  numbers = [10, 20, 30]
  print(max(numbers))  # 좜λ ₯: 30

 

- min(): 반볡 κ°€λŠ₯ν•œ 객체의 μ΅œμ†Ÿκ°’μ„ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  numbers = [10, 20, 30]
  print(min(numbers))  # 좜λ ₯: 10

 

- pow(): x의 y μ œκ³±μ„ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(pow(2, 3))  # 좜λ ₯: 8

 

- range(): μ •μˆ˜ λ²”μœ„λ₯Ό μƒμ„±ν•˜λŠ” ν•¨μˆ˜.

  print(list(range(5)))  # 좜λ ₯: [0, 1, 2, 3, 4]

 

- round(): 숫자λ₯Ό λ°˜μ˜¬λ¦Όν•˜λŠ” ν•¨μˆ˜.

  print(round(3.14159, 2))  # 좜λ ₯: 3.14

 

- sorted(): 반볡 κ°€λŠ₯ν•œ 객체λ₯Ό μ •λ ¬λœ 리슀트둜 λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  numbers = [5, 2, 9, 1]
  print(sorted(numbers))  # 좜λ ₯: [1, 2, 5, 9]

 

- str(): 객체λ₯Ό λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.

  num = 100
  print(str(num))  # 좜λ ₯: '100'

 

- sum(): 반볡 κ°€λŠ₯ν•œ 객체의 합을 λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜.

  numbers = [1, 2, 3, 4, 5]
  print(sum(numbers))  # 좜λ ₯: 15

 

- tuple(): 반볡 κ°€λŠ₯ν•œ 객체λ₯Ό νŠœν”Œλ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.

  print(tuple("hello"))  # 좜λ ₯: ('h', 'e', 'l', 'l', 'o')

 

- zip(): μ—¬λŸ¬ 개의 λ¦¬μŠ€νŠΈλ‚˜ νŠœν”Œμ„ μ§μ§€μ–΄μ£ΌλŠ” ν•¨μˆ˜.

  names = ["Alice", "Bob"]
  scores = [90, 85]
  print(list(zip(names, scores)))  # 좜λ ₯: [('Alice', 90), ('Bob', 85)]
λ°˜μ‘ν˜•

+ Recent posts