๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

2022-11-26-TIL

๐Ÿ“ ์˜ค๋Š˜ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉโ€‹

  • python ์ปดํ”„๋ฆฌํ—จ์…˜
  • ํŒŒ์ด์ฌ ๋ฌธ๋ฒ• ์ค‘ ๊ฐ€์žฅ ์ดํ•ด ์•ˆ๊ฐ€๋Š” ๋ฌธ๋ฒ•. ์ด๊ฒŒ ์ •๋ง ๊ฐ€๋…์„ฑ์ด ์ข‹์€ ๋ฌธ๋ฒ•์ธ๊ฐ€ ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋˜ ๋ฌธ๋ฒ•
  • ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜
    • ์ƒˆ๋กœ์šด ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•
    • ์งง์€ ์ฝ”๋“œ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ
    • ๋ฌธ๋ฒ•์— ์ต์ˆ™ํ•ด์ง€๋ฉด ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์ง„๋‹ค?
    • ์‹œํ€€์Šค์— ๋ชจ๋‘ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
      • ์ŠคํŠธ๋ง
      • ๋ฆฌ์ŠคํŠธ
      • range
      • tuple
numbers = [1, 2, 3]
new_list = []
for n in numbers:
add_1 = n + 1
new_list.append(add_1)

# new_list = [new_item for item in list]
new_list = [n+1 for n in numbers]

new_list = [new_item for item in list]

  • ์–ด๋–ค ์ˆœ์„œ๋กœ ์ฝ์–ด์•ผ ๋ ์ง€ ํ˜ผ๋ž€ ์Šค๋Ÿฌ์šธ์ˆ˜๋„ ์žˆ์ง€๋งŒ?? ์ต์ˆ™ํ•ด์ง€๋ฉด ํŽธํ•˜๋‹ค???

์กฐ๊ฑด์ด ํฌํ•จ๋œ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ ˆ์ด์…˜โ€‹

new_list = [new_item for item in list if test]

names = ["Alex", "Beth", "Caroline", "dave", "Eleanor", "Freddie"]
upper_names = [n.upper() for n in names if len(n) >= 5]
  • replit.com ์‚ฌ์ดํŠธ๋Š” ํ™•์‹คํžˆ ์—ฐ์Šต ์šฉ๋„๋กœ ์ข‹์€ ๊ฒƒ ๊ฐ™๋‹ค.