Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- addEventListener
- Porject
- 비동기
- Import
- 게임
- 참고블로그
- db
- promise
- https://youtube.com/playlist?list=PLuHgQVnccGMA5836CvWfieEQy0T0ov6Jh&si=FTaYv8m21EhO-A2K
- async
- json
- sql
- slow and steady
- JS #프로젝트
- callback
- object
- execCommand
- prj
- js
- ajax
- database
- https://m.blog.naver.com/tt2t2am1118/221010125300
- eport
- mysql
- webpack
- await
- 혼프
- setTimeout()
- 동기
- Project
Archives
- Today
- Total
C-log
Welcome to Python : if문 본문
728x90
- if문 : https://hi-code.tistory.com/116
- while문 : https://hi-code.tistory.com/117
- for문 : https://hi-code.tistory.com/118
| Title | Code | Console |
| if문 | ||
| if문 기본 구조 |
money = True
if money:
print("택시를 타고 가라")
else:
print("걸어가라")
|
택시를 타고 가라 |
| 들여쓰기 방법 indent_error.py(123p) |
money = True
if money:
print("택시를")
print("타고")
print("가라")
|
File "...Quiz.py", line 6 print("가라") IndentationError: unexpected indent |
| 들여쓰기 방법 indent_error.py(124p) |
money = True if money:
print("택시를")
print("타고")
print("가라")
|
|
| and, or ,not |
x or y |=> x,y 둘 중 하나 True = True |
- |
|
x and y |=> x(True),y(True) 둘 다 True = True x and y |=> x(True),y(False) 둘 중 하나 True = False
|
||
|
not x |=> x가 False니까 = True |
||
| in, not in |
print(1 in [1, 2, 3])
print(1 not in [1, 2, 3])
|
True False |
|
print('a' in ('a', 'b', 'c'))
print('j' not in 'python')
|
True True |
|
|
pocket = ['paper', 'cellphone', 'money']
if 'money' in pocket:
print("택시를 타고 가라")
else:
print("걸어가라")
|
택시를 타고 가라` | |
| pass |
pocket = ['paper', 'cellphone', 'money']
if 'money' in pocket:
pass
else:
print("카드를 꺼내라")
|
by 'pass' so nothing print |
| elif |
#Before (only use to ' if ')
pocket = ['paper', 'cellphone', 'money']
card = True
if 'money' in pocket:
print("택시를 타고 가라")
else:
if card:
print("택시를 타고 가라")
else:
print("걸어가라")
|
택시를 타고 가라 |
|
# After pocket = ['paper', 'cellphone', 'money']
card = True
if 'money' in pocket:
print("택시를 타고 가라")
elif card:
print("택시를 타고 가라")
else:
print("걸어가라")
|
택시를 타고 가라 | |
| 조건부 표현식 (conditional expression) |
score = 100
if score >= 60:
message = "success"
print(message)
else:
message = "failure"
print(message)
|
success |
|
score = 100
message = "success" if score >= 60 else "failure"
print(message)
|
success | |
728x90
'📘Python' 카테고리의 다른 글
| Welcome to Python : for문 (0) | 2023.07.09 |
|---|---|
| Welcome to Python : while문 (0) | 2023.07.09 |
| Welcome to Python : 깊은 복사 얕은 복사 (0) | 2023.07.09 |
| Welcome to Python : 집합 자료형 (0) | 2023.07.08 |
| Welcome to Python : 딕셔너리 자료형 (0) | 2023.07.08 |
Comments