4

Как правильно написать выражение с оператором OR в этом случае:

if int(requests.get(url).status_code) in range(200, 299) or in range (400, 499):
    ...
1
  • Кстати, обратите внимание, что range (200,299) не включает 299. То же самое и range(400, 499). 11 авг 2020 в 18:27

3 ответа 3

7

я бы делал это так:

r = requests.get(url)
if 200 <= r.status_code <= 299 or 400 <= r.status_code <= 499:
    ...
6

Вот так правильно:

code = int(requests.get(url).status_code)
if 200 <= code <= 299 or 400 <= code <= 499:
2
code = int(requests.get(url).status_code)
if code in range(200, 299) or code in range (400, 499):

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.