From dcaaaed66752229d31629461d7eafb658eaf5f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AF=E6=B4=81=E7=9A=84=E5=BE=AE=E7=AC=91?= Date: Sun, 18 Aug 2019 20:35:58 +0800 Subject: [PATCH] =?UTF-8?q?Python=20=E6=B5=81=E7=A8=8B=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day-003/Dictionary.py | 1 - day-004/break.py | 4 ++++ day-004/continue.py | 4 ++++ day-004/for.py | 18 ++++++++++++++++++ day-004/if.py | 11 +++++++++++ day-004/pass.py | 8 ++++++++ day-004/range.py | 17 +++++++++++++++++ day-004/while.py | 16 ++++++++++++++++ 8 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 day-004/break.py create mode 100644 day-004/continue.py create mode 100644 day-004/for.py create mode 100644 day-004/if.py create mode 100644 day-004/pass.py create mode 100644 day-004/range.py create mode 100644 day-004/while.py diff --git a/day-003/Dictionary.py b/day-003/Dictionary.py index e71e857..69532f1 100644 --- a/day-003/Dictionary.py +++ b/day-003/Dictionary.py @@ -8,5 +8,4 @@ print (Logo_code['SINA']) # 输出键为 'one' 的值 print (Logo_code.keys()) # 输出所有键 print (Logo_code.values()) # 输出所有值 - print (len(Logo_code)) # 输出字段长度 \ No newline at end of file diff --git a/day-004/break.py b/day-004/break.py new file mode 100644 index 0000000..42ce78f --- /dev/null +++ b/day-004/break.py @@ -0,0 +1,4 @@ +for letter in 'ityouknow': # 第一个实例 + if letter == 'n': # 字母为 n 时中断 + break + print ('当前字母 :', letter) \ No newline at end of file diff --git a/day-004/continue.py b/day-004/continue.py new file mode 100644 index 0000000..7c33c14 --- /dev/null +++ b/day-004/continue.py @@ -0,0 +1,4 @@ +for letter in 'ityouknow': # 第一个实例 + if letter == 'n': # 字母为 n 时跳过输出 + continue + print ('当前字母 :', letter) \ No newline at end of file diff --git a/day-004/for.py b/day-004/for.py new file mode 100644 index 0000000..36b22e9 --- /dev/null +++ b/day-004/for.py @@ -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!") \ No newline at end of file diff --git a/day-004/if.py b/day-004/if.py new file mode 100644 index 0000000..95db858 --- /dev/null +++ b/day-004/if.py @@ -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') \ No newline at end of file diff --git a/day-004/pass.py b/day-004/pass.py new file mode 100644 index 0000000..eb59c2a --- /dev/null +++ b/day-004/pass.py @@ -0,0 +1,8 @@ +while True: + pass # Busy-wait for keyboard interrupt (Ctrl+C) + + +# 这通常用于创建最小结构的类: + +class MyEmptyClass: + pass diff --git a/day-004/range.py b/day-004/range.py new file mode 100644 index 0000000..f5c5a58 --- /dev/null +++ b/day-004/range.py @@ -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]) \ No newline at end of file diff --git a/day-004/while.py b/day-004/while.py new file mode 100644 index 0000000..76d2cf3 --- /dev/null +++ b/day-004/while.py @@ -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") \ No newline at end of file