Inflearn Community Q&A
선생님 질문있습니다
Written on
·
176
0
if ori_price == None or ori_price.get_text() == "": #ori_price.get_text() == "" 는 태그는 있는데 값은 없는거
ori_price = discount_price
ori_price = ori_price.get_text().replace(",","").replace("원","")
discount_price = discount_price.get_text().replace(",","").replace("원","")
같은 코드와 같이 if 문에서 else 없이 이렇게 써도 괜찮나요?? 즉 위의 코드는
if ori_price == None or ori_price.get_text() == "": #ori_price.get_text() == "" 는 태그는 있는데 값은 없는거
ori_price = discount_price
else:
ori_price = ori_price.get_text().replace(",","").replace("원","")
discount_price = discount_price.get_text().replace(",","").replace("원","")
인가요??
pythonmysqlsqlDBMS/RDBMS데이터 엔지니어링
Answer 1
0
funcoding
Instructor
안녕하세요.
정확히는 질문이 무엇인지 제가 잘 이해한 것인지 모르겠는데요. ori_price 태그가 아예 없거나, 있긴 한데 내용이 없는 경우가 있어서, 이 때는 discount_price 도 없기 때문에, 위와 같이 else 로 조건문을 나눠서 쓴 것입니다. 보통은 일반적인 상품에서는 그런 경우가 없는 것 같지만, 가끔 그런 경우가 있고, 이 때 else 문 에 있는 코드가 에러가 나기 때문에, else 로 처리를 했습니다.
감사합니다.






아 간단히 말해서 if else 문과 if문 에서 else를 생략한 구문이 같은지 질문한거였습니다 ㅠㅠ
위의 코드에서 선생님께서 if문에서 else 문을 생략하고 쓰시길래 그부분이 궁금합니다!