Skip to content

Commit 894bac3

Browse files
committed
m
0 parents  commit 894bac3

26 files changed

+296
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Python 100 天学习计划
2+
3+
从小白到工程师的学习之路
4+
5+
- [100 天 Python 学习计划](http://www.ityouknow.com/python/2019/08/01/python-plan-100-day.html)
6+
- [第1天:Python 环境搭建](http://www.ityouknow.com/python/2019/08/01/python-001.html)
7+
- [第2天:Python 基础语法](http://www.ityouknow.com/python/2019/08/02/python-002.html)
8+
- [第3天:Python 变量与数据类型](http://www.ityouknow.com/python/2019/08/03/python-003.html)
9+
- [第4天:Python 流程控制](http://www.ityouknow.com/python/2019/08/04/python-004.html)
10+
- [第4天:Python 流程控制](http://www.ityouknow.com/python/2019/08/04/python-004.html)
11+
- [第5天:Python 函数](http://www.ityouknow.com/python/2019/08/08/python-005.html)
12+
- [第6天:Python 模块和包](http://www.ityouknow.com/python/2019/08/13/python-006.html)
13+
14+
关注公众号:python技术,回复"python"一起学习交流
15+
16+
![](http://favorites.ren/assets/images/python.jpg)

day-001/hello.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello world!")

day-002/identifier.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print("hello");
2+
print("world");

day-002/indent.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if True:
2+
print("neo")
3+
else:
4+
print("smile")

day-002/print.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
x="a"
2+
y="b"
3+
print(x, end=' ')
4+
print(y, end=' ')

day-003/Dictionary.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Logo_code = {
2+
'BIDU':'Baidu',
3+
'SINA':'Sina',
4+
'YOKU':'Youku'
5+
}
6+
print(Logo_code)
7+
# 输出{'BIDU': 'Baidu', 'YOKU': 'Youku', 'SINA': 'Sina'}
8+
print (Logo_code['SINA']) # 输出键为 'one' 的值
9+
print (Logo_code.keys()) # 输出所有键
10+
print (Logo_code.values()) # 输出所有值
11+
print (len(Logo_code)) # 输出字段长度

day-003/List.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday']
2+
print(Weekday[0]) # 输出 Monday
3+
4+
#list 搜索
5+
print(Weekday.index("Wednesday"))
6+
7+
#list 增加元素
8+
Weekday.append("new")
9+
print(Weekday)
10+
11+
# list 删除
12+
Weekday.remove("Thursday")
13+
print(Weekday)

day-003/Sets.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a_set = {1,2,3,4}
2+
# 添加
3+
a_set.add(5)
4+
print(a_set) # 输出{1, 2, 3, 4, 5}
5+
# 删除
6+
a_set.discard(5)
7+
print(a_set) # 输出{1, 2, 3, 4}

day-003/String.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
s = '学习Python'
2+
# 切片
3+
s[0], s[-1], s[3:], s[::-1] # '优', 'n', 'Python', 'nohtyP的雅优'
4+
# 替换,还可以使用正则表达式替换
5+
s.replace('Python', 'Java') # '学习Java'
6+
# 查找,find()、index()、rfind()、rindex()
7+
s.find('P') # 3, 返回第一次出现的子串的下标
8+
s.find('h', 2) # 6, 设定下标2开始查找
9+
s.find('23333') # -1, 查找不到返回-1
10+
s.index('y') # 4, 返回第一次出现的子串的下标
11+
s.index('P') # 不同与find(), 查找不到会抛出异常
12+
# 转大小写, upper()、lower()、swapcase()、capitalize()、istitle()、isupper()、islower()
13+
s.upper() # '学习PYTHON'
14+
s.swapcase() # '学习pYTHON', 大小写互换
15+
s.istitle() # True
16+
s.islower() # False
17+
# 去空格,strip()、lstrip()、rstrip()
18+
# 格式化
19+
s1 = '%s %s' % ('Windrivder', 21) # 'Windrivder 21'
20+
s2 = '{}, {}'.format(21, 'Windridver') # 推荐使用format格式化字符串
21+
s3 = '{0}, {1}, {0}'.format('Windrivder', 21)
22+
s4 = '{name}: {age}'.format(age=21, name='Windrivder')
23+
# 连接与分割,使用 + 连接字符串,每次操作会重新计算、开辟、释放内存,效率很低,所以推荐使用join
24+
l = ['2017', '03', '29', '22:00']
25+
s5 = '-'.join(l) # '2017-03-29-22:00'
26+
s6 = s5.split('-') # ['2017', '03', '29', '22:00']
27+
28+
# encode 将字符转换为字节
29+
str = '学习Python'
30+
print (str.encode()) # 默认编码是 UTF-8 输出:b'\xe5\xad\xa6\xe4\xb9\xa0Python'
31+
print (str.encode('gbk')) # 输出 b'\xd1\xa7\xcf\xb0Python'
32+
# decode 将字节转换为字符
33+
print (str.encode().decode('utf8')) # 输出 '学习Python'
34+
print (str.encode('gbk').decode('gbk')) # 输出 '学习Python'

day-003/Tuple.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
letters = ('a','b','c','d','e','f','g')
2+
print(letters[0]) # 输出 'a'
3+
print(letters[0:3]) # 输出一组 ('a', 'b', 'c')

day-003/number.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/python3
2+
3+
counter = 100 # 整型变量
4+
miles = 1000.0 # 浮点型变量
5+
name = "test" # 字符串
6+
7+
print (counter)
8+
print (miles)
9+
print (name)
10+
11+
12+
print (5 + 4) # 加法 输出 9
13+
print (4.3 - 2) # 减法 输出 2.3
14+
print (3 * 7) # 乘法 输出 21
15+
print (2 / 4) # 除法,得到一个浮点数 输出 0.5
16+
print (2 // 4) # 除法,得到一个整数 输出 0
17+
print (17 % 3) # 取余 输出 2
18+
print (2 ** 5) # 乘方 输出 32

day-003/variable.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = "neo"
2+
print (name)
3+
4+
a, b, c = 1, 2, "neo"
5+
print (a)
6+
print (b)
7+
print (c)

day-004/break.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for letter in 'ityouknow': # 第一个实例
2+
if letter == 'n': # 字母为 n 时中断
3+
break
4+
print ('当前字母 :', letter)

day-004/continue.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for letter in 'ityouknow': # 第一个实例
2+
if letter == 'n': # 字母为 n 时跳过输出
3+
continue
4+
print ('当前字母 :', letter)

day-004/for.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
for letter in 'Python': # 第一个实例
2+
print('当前字母 :', letter)
3+
4+
fruits = ['banana', 'apple', 'mango']
5+
for fruit in fruits: # 第二个实例
6+
print('当前水果 :', fruit)
7+
8+
print("Good bye!")
9+
10+
11+
12+
# 通过索引循环
13+
14+
fruits = ['banana', 'apple', 'mango']
15+
for index in range(len(fruits)):
16+
print('当前水果 :', fruits[index])
17+
18+
print("Good bye!")

day-004/if.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#x = int(input("Please enter an integer: "))
2+
x = -5
3+
if x < 0:
4+
x = 0
5+
print('Negative changed to zero')
6+
elif x == 0:
7+
print('Zero')
8+
elif x == 1:
9+
print('Single')
10+
else:
11+
print('More')

day-004/pass.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
while True:
2+
pass # Busy-wait for keyboard interrupt (Ctrl+C)
3+
4+
5+
# 这通常用于创建最小结构的类:
6+
7+
class MyEmptyClass:
8+
pass

day-004/range.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
for i in range(6):
2+
print(i)
3+
print(range(6),'finish')
4+
5+
for i in range(6,10):
6+
print(i)
7+
print(range(6,10),'finish')
8+
9+
for i in range(6,12,2):
10+
print(i)
11+
print(range(6,12,2),'finish')
12+
13+
14+
# 迭代链表
15+
a = ['i', 'love', 'coding', 'and', 'free']
16+
for i in range(len(a)):
17+
print(i, a[i])

day-004/while.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/python
2+
3+
count = 0
4+
while (count < 9):
5+
print('The count is:', count)
6+
count = count + 1
7+
8+
print("Good bye!")
9+
10+
11+
count = 0
12+
while count < 6:
13+
print(count, " is less than 6")
14+
count = count + 1
15+
else:
16+
print(count, " is not less than 6")

day-005/def.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#定义一个函数
2+
def hello() :
3+
print("Hello World!")
4+
5+
#调用函数
6+
hello()
7+
8+
9+
#定义一个函数
10+
def helloN(name) :
11+
print("Hello World!", name)
12+
13+
#调用函数
14+
helloN('neo')
15+
16+
#定义函数
17+
def add(a,b) :
18+
return a+b
19+
20+
def reduce(a,b) :
21+
return a-b
22+
23+
def multiply(a,b) :
24+
return a*b
25+
26+
def divide(a,b) :
27+
return a/b
28+
29+
#调用函数
30+
print(add(1,2))
31+
print(reduce(12,2))
32+
print(multiply(6,3))
33+
print(divide(12,6))
34+
35+
#定义多个返回值函数
36+
def more(x, y):
37+
nx = x + 2
38+
ny = y - 2
39+
return nx, ny
40+
41+
#调用函数
42+
x, y = more(10, 10)
43+
print(x, y)
44+
45+
46+
#递归函数
47+
def fact(n):
48+
if n==1:
49+
return 1
50+
return n * fact(n - 1)
51+
52+
#调用递归函数
53+
print(fact(6))

day-006/cal/__init__.py

Whitespace-only changes.
140 Bytes
Binary file not shown.
564 Bytes
Binary file not shown.

day-006/cal/calculator.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def add(a,b) :
2+
return a+b
3+
4+
def reduce(a,b) :
5+
return a-b
6+
7+
def multiply(a,b) :
8+
return a*b
9+
10+
def divide(a,b) :
11+
return a/b

day-006/do.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 导入模块
2+
import hello
3+
4+
# 现在可以调用模块里包含的函数了
5+
hello.sayhello()
6+
7+
8+
## 直接导入方法
9+
from hello import sayhello
10+
sayhello()
11+
12+
13+
14+
## 导入所有方法
15+
from hello import *
16+
sayhello()
17+
world()
18+
19+
20+
print("测试包的使用")
21+
22+
import cal.calculator
23+
print(cal.calculator.add(1,2))
24+
25+
26+
from cal import calculator
27+
# 使用包的模块的方法
28+
print(calculator.multiply(3,6))

day-006/hello.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def sayhello():
2+
print("Hello World!")
3+
4+
5+
def world():
6+
print("Python World!")

0 commit comments

Comments
 (0)