///
Search

๋ฆฌ์ŠคํŠธ ๋‚ดํฌ for๋ฌธ

๋ถ„๋ฅ˜
๋ฌธ๋ฒ•
์†์„ฑ
์ƒ์„ฑ์ผ
2023/03/16 08:04
์ตœ์ข… ์ˆ˜์ •
2023/03/16 08:06
[ ํ‘œํ˜„์‹ for ํ•ญ๋ชฉ in ๋ฆฌ์ŠคํŠธ or ํŠœํ”Œ if ์กฐ๊ฑด๋ฌธ ]
Python
๋ณต์‚ฌ
list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] # ๋ฆฌ์ŠคํŠธ ์•ˆ์—์„œ for ๋ฌธ ์‚ฌ์šฉํ•˜๊ธฐ 1 list = [ num * 3 for num in list ] print(list)
Python
๋ณต์‚ฌ
list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] # ๋ฆฌ์ŠคํŠธ ์•ˆ์—์„œ for ๋ฌธ ์‚ฌ์šฉํ•˜๊ธฐ 2: if ๋ฌธ ์‚ฌ์šฉ list = [ num * 3 for num in list if num % 2 == 1 ] print(list)
Python
๋ณต์‚ฌ
# ๋ฆฌ์ŠคํŠธ ์•ˆ์—์„œ for ๋ฌธ ์‚ฌ์šฉํ•˜๊ธฐ 3: ๋‘ ๊ฐœ ์ด์ƒ์˜ for ๋ฌธ list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] list = [ num * num2 for num in list if num % 2 == 1 for num2 in list if num2 % 2 == 1 ] print(list)
Python
๋ณต์‚ฌ
# ๋ฆฌ์ŠคํŠธ ์•ˆ์—์„œ for ๋ฌธ ์‚ฌ์šฉํ•˜๊ธฐ 4: range() ๋ฉ”์„œ๋“œ ํ™œ์šฉ list = [ x * y for x in range(2, 20) for y in range(1, 20) ] print(list)
Python
๋ณต์‚ฌ