Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Dalguring
PythonStudy
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
PythonStudy
/
control_statement
/
if_statement.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
72 lines (62 loc) · 1.69 KB
master
Breadcrumbs
PythonStudy
/
control_statement
/
if_statement.py
Copy path
Top
File metadata and controls
Code
Blame
72 lines (62 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# if 문
"""
파이썬의 if문은
if 조건문:
수행코드1
else:
수행코드2
의 형태로 자바 및 다른 언어와 달리 :(콜론)으로 조건문이 끝났음을 암시하고, 들여쓰기를 통해 if 문 내부 동작임을 구분한다.
"""
money
=
True
if
money
:
print
(
"돈이 있다"
)
else
:
print
(
"돈이 없다"
)
# and, or, not
money
=
2000
card
=
True
if
money
>=
3000
or
card
:
print
(
"택시를 타고 가라"
)
else
:
print
(
"걸어가라"
)
use
=
False
if
not
use
:
# 자바에서는 boolean 타입의 앞에 ! 를 붙여서 bool 값의 반전이 가능하지만, 파이썬에서는 not을 사용한다
print
(
"사용해라"
)
else
:
print
(
"이미 사용했다"
)
# in, not in
# x (not) in 리스트, x (not) in 튜플, x (not) in 문자열 형태를 파이썬에서는 제공한다.
print
(
1
in
[
1
,
2
,
3
])
print
(
1
not
in
[
1
,
2
,
3
])
pocket
=
[
'paper'
,
'cellphone'
,
'money'
]
if
'money'
in
pocket
:
print
(
"택시를 타고 가라"
)
else
:
print
(
"걸어가라"
)
# pass
if
'money'
in
pocket
:
pass
else
:
print
(
"카드를 꺼내라"
)
# elif (else if와 같음)
pocket
=
[
'paper'
,
'cellphone'
]
card
=
True
# elif를 사용하지 않았을 때
if
'money'
in
pocket
:
print
(
"택시를 타고가라"
)
else
:
if
card
:
print
(
"카드로 택시를 타고가라"
)
else
:
print
(
"걸어가라"
)
if
'money'
in
pocket
:
print
(
"돈을 써서 택시를 타고가라"
)
elif
card
:
print
(
"카드로 택시를 타고가라"
)
else
:
print
(
"걸어가라"
)
# 조건부 표현식
# 변수 = 조건문이_참인_경우의_값 if 조건문 else 조건문이_거짓인_경우의_값
score
=
70
message
=
'success'
if
score
>=
60
else
'failure'
print
(
message
)
You can’t perform that action at this time.