let star_image = '⭐'.repeat(star) => star_image에 ⭐을 star번 입력
파이썬
def sum(a,b,c):
return a+b+c
result = sum(1,2,3)
print(result)
=6이라고 출력
ages =[5,10,13,23,25,9]
for a in ages:
if a>20:
print('성인')
else:
print('청소년')
=> {}쓰면 순서대로 출력 안됨! 주의
ages에 하나하나를 a에 넣고 그 a를 밑에 가져다가 쓰자
import requests
rjson = r.json()
rows = rjson['RealtimeCityAir']['row']
for a in rows:
gu_name = a['MSRSTE_NM']
gu_mise = a['IDEX_MVL']
print(gu_name, gu_mise)
=>a를 솎아낸다(한개 일때)
a가 None과 같지 않다
a가 None과 같다
퀴즈
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
soup = BeautifulSoup(data.text, 'html.parser')
trs = soup.select('#old_content > table > tbody > tr')
for tr in trs:
a=tr.select_one('td.title > div > a')
if a is not None:
title=a.text
rank=tr.select_one('td:nth-child(1) > img')['alt']
star=tr.select_one('td.point').text
print(rank, title, star)
속성은 .text가 아니라 ['alt']이다