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 }}
Gnotes
python
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
python
/
example
/
day02
/
loop.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
50 lines (38 loc) · 1.3 KB
master
Breadcrumbs
python
/
example
/
day02
/
loop.py
Copy path
Top
File metadata and controls
Code
Blame
50 lines (38 loc) · 1.3 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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
for
l
in
'Python'
:
# 第一个实例
print
(
'当前字母 :'
,
l
)
fruits
=
[
'banana'
,
'apple'
,
'mango'
]
for
f
in
fruits
:
# 第二个实例
print
(
'当前字母 :'
,
f
)
print
(
'------------------'
)
for
index
in
range
(
len
(
fruits
)):
print
(
'当前水果 :'
,
fruits
[
index
])
print
(
'------------------'
)
for
num
in
range
(
10
,
20
):
# 迭代 10 到 20 之间的数字
for
i
in
range
(
2
,
num
):
# 根据因子迭代
if
num
%
i
==
0
:
# 确定第一个因子
j
=
num
/
i
# 计算第二个因子
print
(
'%d 等于 %d * %d'
%
(
num
,
i
,
j
))
break
# 跳出当前循环
else
:
# 循环的 else 部分
print
(
num
,
'是一个质数'
)
print
(
'------------------'
)
for
letter
in
'Python'
:
# 第一个实例
if
letter
==
'h'
:
break
print
(
'当前字母 :'
,
letter
)
print
(
'------------------'
)
var
=
10
# 第二个实例
while
var
>
0
:
print
(
'当前变量值 :'
,
var
)
var
=
var
-
1
if
var
==
5
:
# 当变量 var 等于 5 时退出循环
break
print
(
'------------------'
)
# 输出 Python 的每个字母
for
letter
in
'Python'
:
if
letter
==
'h'
:
pass
print
(
'这是 pass 块'
)
print
(
'当前字母 :'
,
letter
)
You can’t perform that action at this time.