Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Python 流程控制
- Loading branch information
Showing
8 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
for letter in 'ityouknow': # 第一个实例 | ||
if letter == 'n': # 字母为 n 时中断 | ||
break | ||
print ('当前字母 :', letter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
for letter in 'ityouknow': # 第一个实例 | ||
if letter == 'n': # 字母为 n 时跳过输出 | ||
continue | ||
print ('当前字母 :', letter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
for letter in 'Python': # 第一个实例 | ||
print('当前字母 :', letter) | ||
|
||
fruits = ['banana', 'apple', 'mango'] | ||
for fruit in fruits: # 第二个实例 | ||
print('当前水果 :', fruit) | ||
|
||
print("Good bye!") | ||
|
||
|
||
|
||
# 通过索引循环 | ||
|
||
fruits = ['banana', 'apple', 'mango'] | ||
for index in range(len(fruits)): | ||
print('当前水果 :', fruits[index]) | ||
|
||
print("Good bye!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#x = int(input("Please enter an integer: ")) | ||
x = -5 | ||
if x < 0: | ||
x = 0 | ||
print('Negative changed to zero') | ||
elif x == 0: | ||
print('Zero') | ||
elif x == 1: | ||
print('Single') | ||
else: | ||
print('More') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
while True: | ||
pass # Busy-wait for keyboard interrupt (Ctrl+C) | ||
|
||
|
||
# 这通常用于创建最小结构的类: | ||
|
||
class MyEmptyClass: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
for i in range(6): | ||
print(i) | ||
print(range(6),'finish') | ||
|
||
for i in range(6,10): | ||
print(i) | ||
print(range(6,10),'finish') | ||
|
||
for i in range(6,12,2): | ||
print(i) | ||
print(range(6,12,2),'finish') | ||
|
||
|
||
# 迭代链表 | ||
a = ['i', 'love', 'coding', 'and', 'free'] | ||
for i in range(len(a)): | ||
print(i, a[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/python | ||
|
||
count = 0 | ||
while (count < 9): | ||
print('The count is:', count) | ||
count = count + 1 | ||
|
||
print("Good bye!") | ||
|
||
|
||
count = 0 | ||
while count < 6: | ||
print(count, " is less than 6") | ||
count = count + 1 | ||
else: | ||
print(count, " is not less than 6") |