Skip to content

Commit 5d6e902

Browse files
committed
整理代码
1 parent 0687509 commit 5d6e902

30 files changed

Lines changed: 149 additions & 88 deletions

.idea/workspace.xml

Lines changed: 94 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 导入socket库:
22
import socket
3+
34
# 创建一个socket:
45
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
56
# 建立连接:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from bs4 import BeautifulSoup
33
from lxml import etree
44
import os
5+
56
url = 'http://www.toutiao.com/a6402018208622510337/#p=1'
67
r = urllib.request.urlopen(url)
78
html = r.read().decode('utf-8')

Python基础示例代码/切片.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
str = [1, 4, 5, 6, 7, 9, 11, 14, 16]
2+
print(str[-1:]) # 截取最后一个元素
3+
print(str[0:3]) # 截取第一位到第三位的字符
4+
print(str[:]) # 截取字符串的全部字符
5+
print(str[6:]) # 截取第七个字符到结尾
6+
print(str[:-3]) # 截取从头开始到倒数第三个字符之前
7+
print(str[2]) # 截取第三个字符
8+
print(str[::-1]) # 创造一个与原字符串顺序相反的字符串
9+
print(str[-3:-1]) # 截取倒数第三位与倒数第一位之前的字符
10+
print(str[-3:]) # 截取倒数第三位到结尾
11+
print(str[:-5:-3]) # 逆序截取后个数,每3个取一个,而且取是逆向取值
12+
print(str[:10:2]) # 前10个数,每两个取一个
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
L1 = ['Hello', 'World', 18, 'Apple', None]
22
L2 = [s.lower() for s in L1 if isinstance(s, str)]
3-
print(L2)
3+
print(L2)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# 生成[1x1, 2x2, 3x3, ..., 10x10]
2-
print([x*x for x in range(1,11)])
2+
print([x * x for x in range(1, 11)])
33
# 可以使用两层循环,可以生成全排列
44
print([m + n for m in 'ABC' for n in 'XYZ'])
55

66
import os
7-
print([d for d in os.listdir('.')])
7+
8+
print([d for d in os.listdir('.')])
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
def f2(a, b, c=0, *, d, **kw):
22
print('a =', a, 'b =', b, 'c =', c, 'd =', d, 'kw =', kw)
3-
f2(1, 2, d=99, ext=None,ok=22)
3+
4+
5+
f2(1, 2, d=99, ext=None, ok=22)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
23
print('开始程序')
34
time.sleep(4)
4-
print('延时结束')
5+
print('延时结束')

0 commit comments

Comments
 (0)