updated_at: 2024-12-14 16:09

제어문 (control-statement)

if

if wikibooks_cur_price >= 10000:
        print("Buy 10")"

if ~ else

if wikibooks_cur_price >= 10000:
  print("Buy 10")
else:
  print("Holding")


### if ~ elif ~else
` ``
if price < 1000:
  bid = 1
elif price >= 1000 and price < 5000:
  bid = 5
elif price >= 5000 and price < 10000:
  bid = 10

for

for와 range

for i in range(0, 11):
  print(i)

for와 리스트

interest_stocks = ["Naver", "Samsung", "SK Hynix"]
for company in interest_stocks:
  print("company: Buy 10")

for와 튜플

interest_stocks = ("Naver", "Samsung", "SK Hynix")
for company in interest_stocks:
  print("%s: Buy 10" % company)

for와 딕셔너리

for company, stock_num in interest_stocks.items():
  print("%s: Buy %s" % (company, stock_num))

while

wikibooks = 10000
day = 1
 while day < 6:
    wikibooks = wikibooks + wikibooks * 0.3
    day = day + 1

while과 if

num = 0
while num <= 10:
  if num % 2 == 1:
    print(num)
  num += 1

break와 continue

while 1:
  print(“Find stocks”)
  break
num = 0
while num < 10:
  num += 1
  if num == 5:
    continue
  print(num)

중첩 루프

for i in [1, 2, 3, 4]:
  for j in [1, 2, 3, 4]:
    pass
for floor in apart:
  for room in floor:
    print("Newspaper delivery: ", room)

if not

if not False:
  .....
if not 0:
  .....
if not []:
  .....
if not {}:
  .....
if not "":
  .....
if not None:
  .....
if not ():
  .....
1 == 1 #  -> True
1 != 1 #  -> False
평점을 남겨주세요
평점 : 5.0
총 투표수 : 1

질문 및 답글