[๐ŸงจํŒŒ์ด์ฌ ๊ธฐ์ดˆ2] ์ œ์–ด๋ฌธ(์กฐ๊ฑด๋ฌธ & ๋ฐ˜๋ณต๋ฌธ)

์•ˆ์ง€์ˆ˜ยท2023๋…„ 1์›” 30์ผ
0

์กฐ๊ฑด๋ฌธ

  • ๋“ค์—ฌ์“ฐ๊ธฐ ์ค‘์š”
if money>=3000:
	print("ํƒ์‹œ ํƒ€๊ณ  ๊ฐ€๋ผ")
else:
	print("๊ฑธ์–ด๊ฐ€๋ผ")
>> ๊ฑธ์–ด๊ฐ€๋ผ

๐Ÿ‘‘ X in s, X not in s

pocket = ['paper', 'cellphone', 'money']
if 'money' in pocket:
	print("ํƒ์‹œ๋ฅผ ํƒ€๊ณ  ๊ฐ€๋ผ")
else:
	pass #์•„๋ฌด ์ผ๋„ ์ผ์–ด๋‚˜์ง€ ์•Š๊ฒŒ ์„ค์ •
>> ํƒ์‹œ๋ฅผ ํƒ€๊ณ ๊ฐ€๋ผ

--> pass: ์•„๋ฌด ์ผ๋„ ํ•˜์ง€ ์•Š๊ฒŒ ์„ค์ •!

๐Ÿ‘‘ ์กฐ๊ฑด๋ถ€ ํ‘œํ˜„์‹

Message = "success" if score>=60 else "failure"

๋ฐ˜๋ณต๋ฌธ

๐Ÿ‘‘ While๋ฌธ

coffee = 10
money = 300
while money:
	print("๋ˆ์„ ๋ฐ›์•˜์œผ๋‹ˆ ์ปคํ”ผ๋ฅผ ์ค๋‹ˆ๋‹ค.")
    coffee = coffee - 1
    print("๋‚จ์€ ์ปคํ”ผ์˜ ์–‘์€ %d๊ฐœ์ž…๋‹ˆ๋‹ค." %coffee)
    if not coffe:
    	print("์ปคํ”ผ๊ฐ€ ๋‹ค ๋–จ์–ด์กŒ์Šต๋‹ˆ๋‹ค. ํŒ๋งค๋ฅผ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค.")
    	break;
  • break: ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ฐ˜๋ณต๋ฌธ ๋น ์ ธ๋‚˜์˜ด
  • continue: ์‹คํ–‰์„ ์ค‘๋‹จํ•˜๊ณ  ๋‹ค์‹œ ๋ฐ˜๋ณต๋ฌธ ์ฒ˜์Œ์œผ๋กœ ๋Œ์•„๊ฐ

๐Ÿ‘‘ for๋ฌธ

a = [(1,2), (3,4), (5,6)]
for (first, last) in a:
	print(first+last)
    
>> 
3
7
11
sum = 0
for i in range(1,11)
	print(i, end=" ")
	sum = sum+i
print(sum)
>> 55
  • for๊ณผ ragneํ•จ์ˆ˜ ํ•จ๊ป˜ ์ž์ฃผ ์‚ฌ์šฉ(๋ฒ”์œ„ ์ง€์ •)
  • end: print๋ฌธ ๋ ์ชฝ์— ๋Œ€ํ•œ ์ถœ๋ ฅ ์ €์žฅ(์—ฌ๊ธฐ์„  " ")
a = [1,2,3,4]
result = [num*3 for num in a]
print(Result)
>> [3,6,9,12]
profile
์ง€์ˆ˜์˜ ์ทจ์ค€, ๊ฐœ๋ฐœ์ผ๊ธฐ

0๊ฐœ์˜ ๋Œ“๊ธ€