Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhenguo committed Feb 27, 2021
2 parents 7a47666 + 9dfc6c9 commit adcf19a
Show file tree
Hide file tree
Showing 241 changed files with 807 additions and 205 deletions.
3 changes: 3 additions & 0 deletions md/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ relu(5) # 5
relu(-1) # 0
```



<center>[下一个例子](2.md)</center>
3 changes: 3 additions & 0 deletions md/10.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ int(x, base =10) , x可能为字符串或数值,将x 转换为一个普通整
In [1]: int('12',16)
Out[1]: 18
```


<center>[上一个例子](9.md) [下一个例子](11.md)</center>
4 changes: 3 additions & 1 deletion md/100.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ print(r) # False
r = is_permutation('work', 'woo')
print(r) # False

```
```

<center>[上一个例子](99.md) [下一个例子](101.md)</center>
4 changes: 3 additions & 1 deletion md/101.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ print(r) # True

r = is_rotation('greatman', 'maneatgr')
print(r) # False
```
```

<center>[上一个例子](100.md) [下一个例子](102.md)</center>
4 changes: 3 additions & 1 deletion md/102.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ Out[88]: <re.Match object; span=(0, 5), match='000.2'>

两个式子连接起来就是最终的结果:

`^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$`
`^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$`

<center>[上一个例子](101.md) [下一个例子](103.md)</center>
4 changes: 3 additions & 1 deletion md/103.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Out[5]: './data/py/test'

In [6]: ext
Out[6]: '.py'
```
```

<center>[上一个例子](102.md) [下一个例子](104.md)</center>
4 changes: 3 additions & 1 deletion md/104.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ Out[12]: './data/py'

In [13]: ifile
Out[13]: 'test.py'
```
```

<center>[上一个例子](103.md) [下一个例子](105.md)</center>
4 changes: 3 additions & 1 deletion md/105.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ def main():
new_ext = '.' + new_ext

batch_rename(work_dir, old_ext, new_ext)
```
```

<center>[上一个例子](104.md) [下一个例子](106.md)</center>
4 changes: 3 additions & 1 deletion md/106.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ xls_to_xlsx('./data')
# 输出结果:
# ['cut_words.csv', 'email_list.xlsx', 'email_test.docx', 'email_test.jpg', 'email_test.xlsx', 'geo_data.png', 'geo_data.xlsx',
'iotest.txt', 'pyside2.md', 'PySimpleGUI-4.7.1-py3-none-any.whl', 'test.txt', 'test_excel.xlsx', 'ziptest', 'ziptest.zip']
```
```

<center>[上一个例子](105.md) [下一个例子](107.md)</center>
4 changes: 3 additions & 1 deletion md/107.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ def find_file(work_dir,extension='jpg'):

r = find_file('.','md')
print(r) # 返回所有目录下的md文件
```
```

<center>[上一个例子](106.md) [下一个例子](108.md)</center>
4 changes: 3 additions & 1 deletion md/108.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ def batch_zip(start_dir):
batch_zip('./data/ziptest')


```
```

<center>[上一个例子](107.md) [下一个例子](109.md)</center>
4 changes: 3 additions & 1 deletion md/109.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ def hash_cry32(s):

print(hash_cry32(1)) # c4ca4238a0b923820dcc509a6f75849b
print(hash_cry32('hello')) # 5d41402abc4b2a76b9719d911017c592
```
```

<center>[上一个例子](108.md) [下一个例子](110.md)</center>
3 changes: 3 additions & 0 deletions md/11.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ base为底的exp次幂,如果mod给出,取余
In [1]: pow(3, 2, 4)
Out[1]: 1
```


<center>[上一个例子](10.md) [下一个例子](12.md)</center>
4 changes: 3 additions & 1 deletion md/110.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
30 31
```
```

<center>[上一个例子](109.md) [下一个例子](111.md)</center>
4 changes: 3 additions & 1 deletion md/111.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ print(print_leap_str % mydate.year)

```python
2019年不是闰年
```
```

<center>[上一个例子](110.md) [下一个例子](112.md)</center>
4 changes: 3 additions & 1 deletion md/112.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ print(f'{mydate.year}年-{mydate.month}月共有{days}天\n')
2019-12月的第一天是那一周的第6

2019-12月共有31
```
```

<center>[上一个例子](111.md) [下一个例子](113.md)</center>
4 changes: 3 additions & 1 deletion md/113.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ print(f"当月第一天:{month_first_day}\n")

```python
# 当月第一天:2019-12-01
```
```

<center>[上一个例子](112.md) [下一个例子](114.md)</center>
4 changes: 3 additions & 1 deletion md/114.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ print(f"当月最后一天:{month_last_day}\n")

```python
当月最后一天:2019-12-31
```
```

<center>[上一个例子](113.md) [下一个例子](115.md)</center>
4 changes: 3 additions & 1 deletion md/115.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ print(today_time) # 2019-12-22 18:02:33.398894

local_time = localtime()
print(strftime("%Y-%m-%d %H:%M:%S", local_time)) # 转化为定制的格式 2019-12-22 18:13:41
```
```

<center>[上一个例子](114.md) [下一个例子](116.md)</center>
4 changes: 3 additions & 1 deletion md/116.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ struct_time = strptime('2019-12-22 10:10:08', "%Y-%m-%d %H:%M:%S")
print(struct_time) # struct_time类型就是time中的一个类

# time.struct_time(tm_year=2019, tm_mon=12, tm_mday=22, tm_hour=10, tm_min=10, tm_sec=8, tm_wday=6, tm_yday=356, tm_isdst=-1)
```
```

<center>[上一个例子](115.md) [下一个例子](117.md)</center>
4 changes: 3 additions & 1 deletion md/117.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Out[2]: time.struct_time(tm_year=2019, tm_mon=12, tm_mday=22, tm_hour=18, tm_min

print(strftime("%m-%d-%Y %H:%M:%S", localtime())) # 转化为定制的格式
# 这是字符串表示的时间: 12-22-2019 18:26:21
```
```

<center>[上一个例子](116.md) [下一个例子](118.md)</center>
4 changes: 3 additions & 1 deletion md/118.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ print(t) # <_MainThread(MainThread, started 139908235814720)>
print(t.getName()) # MainThread
print(t.ident) # 139908235814720
print(t.isAlive()) # True
```
```

<center>[上一个例子](117.md) [下一个例子](119.md)</center>
4 changes: 3 additions & 1 deletion md/119.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ my_thread().start()
打印i:1
```

至此,多线程相关的核心知识点,已经总结完毕。但是,仅仅知道这些,还不够!光纸上谈兵,当然远远不够。
至此,多线程相关的核心知识点,已经总结完毕。但是,仅仅知道这些,还不够!光纸上谈兵,当然远远不够。

<center>[上一个例子](118.md) [下一个例子](120.md)</center>
3 changes: 3 additions & 0 deletions md/12.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Out[11]: 10.022
In [12]: round(10.05,1)
Out[12]: 10.1
```


<center>[上一个例子](11.md) [下一个例子](13.md)</center>
4 changes: 3 additions & 1 deletion md/120.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ threads = [threading.Thread(name='t%d'%(i,),target=print_time) for i in range(3)
当前线程t2,打印结束时间为:2020-01-12 02:27:16.107564
当前线程t0,打印结束时间为:2020-01-12 02:27:16.107290
当前线程t1,打印结束时间为:2020-01-12 02:27:16.107741
```
```

<center>[上一个例子](119.md) [下一个例子](121.md)</center>
4 changes: 3 additions & 1 deletion md/121.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ NO!



但是在本例中,`a = a + 1`这种修改操作,花费的时间太短了,短到我们无法想象。所以,线程间轮询执行时,都能get到最新的a值。所以,暴露问题的概率就变得微乎其微。
但是在本例中,`a = a + 1`这种修改操作,花费的时间太短了,短到我们无法想象。所以,线程间轮询执行时,都能get到最新的a值。所以,暴露问题的概率就变得微乎其微。

<center>[上一个例子](120.md) [下一个例子](122.md)</center>
4 changes: 3 additions & 1 deletion md/122.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ t9 adds a to 1: 1
tmp = a + 1
time.sleep(0.2) # 延时0.2秒,模拟写入所需时间
a = tmp
```
```

<center>[上一个例子](121.md) [下一个例子](123.md)</center>
4 changes: 3 additions & 1 deletion md/123.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ t9 adds a to 1: 10

程序中只有一把锁,通过 `try...finally`还能确保不发生死锁。但是,当程序中启用多把锁,还是很容易发生死锁。

注意使用场合,避免死锁,是我们在使用多线程开发时需要注意的一些问题。
注意使用场合,避免死锁,是我们在使用多线程开发时需要注意的一些问题。

<center>[上一个例子](122.md) [下一个例子](124.md)</center>
4 changes: 3 additions & 1 deletion md/124.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ Out[69]: time.struct_time(tm_year=2020, tm_mon=2, tm_mday=22, tm_hour=11, tm_min
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
```
```

<center>[上一个例子](123.md) [下一个例子](125.md)</center>
4 changes: 3 additions & 1 deletion md/125.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ def search_n(s, c, n):

print(search_n("fdasadfadf", "a", 3))# 结果为7,正确
print(search_n("fdasadfadf", "a", 30))# 结果为-1,正确
```
```

<center>[上一个例子](124.md) [下一个例子](126.md)</center>
4 changes: 3 additions & 1 deletion md/126.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ def fibonacci(n):


list(fibonacci(5)) # [1, 1, 2, 3, 5]
```
```

<center>[上一个例子](125.md) [下一个例子](127.md)</center>
4 changes: 3 additions & 1 deletion md/127.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ def find_all_duplicates(lst):


find_all_duplicates([1, 2, 2, 3, 3, 3]) # [2,3]
```
```

<center>[上一个例子](126.md) [下一个例子](128.md)</center>
4 changes: 3 additions & 1 deletion md/128.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ def sumc(*c):
#Counter({'orange': 3, 'computer': 3, 'apple': 1, 'abc': 1, 'face': 1})
sumc(a, b, ['abc'], ['face', 'computer'])

```
```

<center>[上一个例子](127.md) [下一个例子](129.md)</center>
4 changes: 3 additions & 1 deletion md/129.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ cloud
{'date': '2019-12-14', 'weather': 'cloud'}
sunny
{'date': '2019-12-13', 'weather': 'sunny'}
```
```

<center>[上一个例子](128.md) [下一个例子](130.md)</center>
3 changes: 3 additions & 0 deletions md/13.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ i = 3
print(1 < i < 3) # False
print(1 < i <= 3) # True
```


<center>[上一个例子](12.md) [下一个例子](14.md)</center>
4 changes: 3 additions & 1 deletion md/130.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ sunny
{'date': '2019-12-13', 'weather': 'sunny'}
```

注意这个结果与上面结果有些微妙不同,这个更多是我们想看到和使用更多的。
注意这个结果与上面结果有些微妙不同,这个更多是我们想看到和使用更多的。

<center>[上一个例子](129.md) [下一个例子](131.md)</center>
4 changes: 3 additions & 1 deletion md/131.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ cloud
{'date': '2019-12-14', 'weather': 'cloud'}
sunny
{'date': '2019-12-13', 'weather': 'sunny'}
```
```

<center>[上一个例子](130.md) [下一个例子](132.md)</center>
4 changes: 3 additions & 1 deletion md/132.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ In [8]:(i+1 for i in a)
OUT [8]:<generator object <genexpr> at 0x000002AC7FFA8CF0>
```

生成器每迭代一步吐出(`yield`)一个元素并计算和聚合后,进入下一次迭代,直到终点。
生成器每迭代一步吐出(`yield`)一个元素并计算和聚合后,进入下一次迭代,直到终点。

<center>[上一个例子](131.md) [下一个例子](133.md)</center>
3 changes: 3 additions & 0 deletions md/133.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ In [3]: for day in getEverydaySince(2020,2,1):
2020-02-10
```



<center>[上一个例子](132.md) [下一个例子](134.md)</center>
4 changes: 3 additions & 1 deletion md/134.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ def divide_iter(lst, n):

list(divide_iter([1, 2, 3, 4, 5], 0)) # [[1, 2, 3, 4, 5]]
list(divide_iter([1, 2, 3, 4, 5], 2)) # [[1, 2, 3], [4, 5]]
```
```

<center>[上一个例子](133.md) [下一个例子](135.md)</center>
4 changes: 3 additions & 1 deletion md/135.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ def function(lst):
else:
yield i
print(list(function(a))) # [1, 2, 3, 4, 5, 6, 7, 8, 'python', 6, 9]
```
```

<center>[上一个例子](134.md) [下一个例子](136.md)</center>
Loading

0 comments on commit adcf19a

Please sign in to comment.