from requests import get

websites=[
"google.com",
"https://httpstat.us/502",
"https://httpstat.us/404",
"https://httpstat.us/300",
"https://httpstat.us/200",
"https://httpstat.us/101"
]
#https://httpstat.us/xxx is service for generating HTTP codes

results={}

for website in websites:
if not website.startswith("https://"):
website = f"https://{website}"
code = get(website).status_code
if code >= 500:
results[website] = "5xx / server error"
elif code >= 400:
results[website] = "4xx / client error"
elif code >= 300:
results[website] = "3xx / redirection "
elif code >= 200:
results[website] = "2xx / successful"
elif code >= 100:
results[website] = "1xx / informational response"

print(results)

반응형

'IT & Programming > python' 카테고리의 다른 글

파이선 자료구조  (0) 2023.03.22

list의 method 종류들을 보면

1. cound(내 list의 특정value가 몇개 있는지 알려준다.)
2. clear(list에있는 모든 value들을 없엔다. list에게 mutate를(modufy) 한것이다.)
3. reverse(list의 value들을 앞뒤 순서 바꿔버린다.)
4. append(list에 value을 추가할 수가 있다.)
5. remove(list에 특정 value을 없엘 수가 있다.)

list에 특정 값을 갖고 싶다고할때 먼저 list를 가리키는 variable에 접근해서 [ ] 대활호를 열고, 원하는 값의 숫자 순서 맞게 순서를 쓰면된다.

주의해야할 점은 pc는 숫자를 0부터 세기 때문에 ex) 만약 list 3번째에(사람이 숫자 세는 방식) 원하느 값이 있다면 숫자 2를(pc가 숫자 세는 방식) 써야한다.

ex)
```python
days_of_week = ["Mon", "Tue", "Wed", "Thur", "Fri"]

print(days_of_week[3])

 

List 리스트 자료형

리스트를 사용하면 1, 3, 5, 7, 9 숫자 모음을
다음과 같이 간단하게 표현할 수 있다.

리스트명 = [요소1, 요소2, 요소3, ...]
example >>> odd = [1, 3, 5, 7, 9]

https://wikidocs.net/14

 

튜플 Tuple 자료형 = 불변 , 순서

리스트는 [ ]으로 둘러싸지만 튜플은 ( )으로 둘러싼다.
리스트는 그 값의 생성, 삭제, 수정이 가능하지만
튜플은 그 값을 바꿀 수 없다.

example >>>>>>
t1 = ()
>>> t2 = (1,)
>>> t3 = (1, 2, 3)
>>> t4 = 1, 2, 3
>>> t5 = ('a', 'b', ('ab', 'cd'))

https://wikidocs.net/15

 

딕셔너리 Dictionary 자료형 = 키

딕셔너리는 Key와 Value를 한 쌍으로 갖는 자료형이다.

example >> {Key1: Value1, Key2: Value2, Key3: Value3, ...}
>>> dic = {'name':'pey', 'phone':'0119993323', 'birth': '1118'}

https://wikidocs.net/16

 

02-5 딕셔너리 자료형

`[추천 동영상 강의]` : [https://www.youtube.com/watch?v=BmXDox6ZFzo](https://www.youtube.com/watch?v=BmXDo…

wikidocs.net

 

Summary of Data Structures
1) Lists
- how to write : [ ]
- properties: mutable, multi-type data
- methods: append # Add elements in the latter part

2) Tuple
- how to write: ()
- properties: not mutable, multi-type data
- methods: restricted

3) Dictionary
- how to write: {key: value}
- properties: mutable, multi-type data

반응형

'IT & Programming > python' 카테고리의 다른 글

http status  (0) 2023.03.22

+ Recent posts