Skip to content

Commit 3c8497a

Browse files
committed
Python matrix
1 parent 9ffea31 commit 3c8497a

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

taiyangxue/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [showdata](https://github.com/JustDoPython/python-examples/tree/master/taiyangxue/showdata) : Flask + echarts 轻松搞定 nginx 日志可视化
1515
- [dice](https://github.com/JustDoPython/python-examples/tree/master/taiyangxue/dice) : 做硬核老爸,我用 Python
1616
- [python39](https://github.com/JustDoPython/python-examples/tree/master/taiyangxue/python39) : 你在享受十一长假时,Python 已悄悄地变了
17+
- [matrix](https://github.com/JustDoPython/python-examples/tree/master/taiyangxue/matrix) : Python 世界的黑客帝国
1718

1819
---
1920

taiyangxue/matrix/chain.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 命令行下执行
2+
# 思考下下面表达式的值
3+
4+
(False == False) in [False] # 合乎常理
5+
False == (False in [False]) # 也没问题
6+
False == False in [False] # 现在感觉如何?
7+
True is False == False
8+
False is False is False
9+
1 > 0 < 1
10+
(1 > 0) < 1
11+
1 > (0 < 1)

taiyangxue/matrix/eatjs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
some_dict = {}
2+
some_dict[5.5] = "Ruby"
3+
some_dict[5.0] = "JavaScript"
4+
some_dict[5] = "Python"
5+
6+
print(some_dict[5.5]) # Ruby
7+
print(some_dict[5.0]) # Python Javascript 去哪了

taiyangxue/matrix/is.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 命令行下执行
2+
a = 256
3+
b = 256
4+
a is b # 值是什么
5+
6+
a = 257
7+
b = 257
8+
a is b # 值是什么
9+
10+
a = []
11+
b = []
12+
a is b # 值是什么
13+
14+
a = tuple()
15+
b = tuple()
16+
a is b # 值是什么

taiyangxue/matrix/sting.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 命令行下执行
2+
3+
a = "some_string"
4+
id(a)
5+
id("some" + "_" + "string") # 不同方式创建的字符串实质是一样的.
6+
7+
a = "wtf"
8+
b = "wtf"
9+
a is b # 想想结果是什么
10+
11+
a = "wtf!"
12+
b = "wtf!"
13+
a is b # 结果又会是什么

taiyangxue/matrix/walrus.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 海象操作符
2+
3+
a = [1,2,3,4,5]
4+
if n := len(n) > 4:
5+
print(n)
6+
7+
# 命令行中执行
8+
a = "wtf_walrus"
9+
a := "wtf_walrus" # 报错!
10+
(a := "wtf_walrus") # 奇迹发生,竟然通过了!
11+
12+
a = 6, 9 # 元组赋值
13+
14+
(a := 6, 9) # 海象赋值,表达式结果正常
15+
# 现在 a 的值是多少?
16+
17+
a, b = 6, 9 # 解包赋值
18+
(a, b = 16, 19) # Oh no!
19+
20+
(a, b := 16, 19) # 这里竟然打印出三员元组!
21+
22+
# 现在的 a 是多少?

0 commit comments

Comments
 (0)