(1) python 6일차
(2) recap & study
*강의 링크*
*For Loops*
websites = (
"google.com",
"airbnb.com",
"facebook.com"
) #using tuple (list is almost same)
for website in websites: #get each components in wesbsite tuples
print(website)
For문: 위의 예시처럼, 여러 자료형(tuple, list)등에서
각각의 item을 이용해서 코드를 실행시 반복문을 사용
*URL Formatting*
websites = (
"google.com",
"https://airbnb.com",
"facebook.com"
) #using tuple (list is almost same)
for website in websites: #get each components in wesbsite tuples
if not website.startswith("https://"): #not start with "https://"
website = f"https://{website}" #using f-formatting
print(website)
계속 "f"를 붙이는 이유는 f-formatting이라고
하는 방식을 사용하기 위해서 이다.
공식 문서 = > docs
startswith: 문자열이 특정 문자로 시작하는 여부를 boolean으로 반
*Requests*
from requests import get #request라이브러리에서 get 함수를 불러옴
websites = (
"google.com",
"https://airbnb.com",
"facebook.com"
)
for website in websites:
if not website.startswith("https://"):
website = f"https://{website}"
print(website)
PyPi: 여러 파이썬 패키지들을 모아놓은 사이트?
pip명령어로 바로 설치할 수 있게 도움
링크 => PyPi
pip: 파이썬으로 작성된 패키지 라이브러리들을 관리하는 시스템
우분투에서 apt-get과 비슷한 구조, 파이썬에 기본적으로 포함되어있다
*Status Codes*
from requests import get #request라이브러리에서 get 함수를 불러옴
websites = (
"google.com",
"https://airbnb.com",
"facebook.com"
)
for website in websites:
if not website.startswith("https://"):
website = f"https://{website}"
response = get(website) #get(using requests) take response
print(response) #print the result
get: request를 사용해서 HTTP코드를 받아옴
HTTP코드: 200 요청 성공, 404 요청 실패우리가 에러날때 주로 보는
404 error(서버에서 리소스를 못받음)가 여기에 포함된다
docs = > docs link
(3) assignment
*조건*
- 아래 배열의 숫자를 합하는 코드 작성 & 결과 프린트
- numbers = [1, "💖", 2, "🔥", 3, "⭐️", 4, "💖", 5, "🔥", 6, "⭐️", 7, "💖", 8, "🔥", 9, "⭐️", 10, "💖", 11, "🔥", 12, "⭐️", 13, "💖", 14, "🔥", 15, "⭐️", 16]
- 결과값은 136