Skip to content

Commit 9e40368

Browse files
committed
视频将到了python迷惑行为:自我修改问题
1 parent 6ead6bb commit 9e40368

File tree

12 files changed

+140
-16
lines changed

12 files changed

+140
-16
lines changed

012 三目运算/学习摘要

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
《内容摘要》Video Abstract
2+
3+
一元二元三元(目)是什么意思
4+
三元运算符写法辨析
5+
if语句自动布尔转化
6+
压缩if语句成一行
7+
为什么三元运算符总写不对
8+
js、C语言,java、C++、php与python三目的区别
9+
学习三目运算符的意义
10+
三元运算符二层嵌套写法
11+
用三元运算符写一个《50%概率执行一个函数》
12+
带返回值的三元运算符写法

013 reverse/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
arr = [1, 2, 4, 5]
2+
for i, n in enumerate(reversed(arr)):
3+
# print(i, n)
4+
...
5+
for i, n in reversed(list(enumerate(arr))):
6+
print(i, n)

013 sort/test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
arr2 = [(1, 2), (2, 2), (5, 0)]
2+
3+
from functools import cmp_to_key
4+
5+
6+
def cmp(a, b):
7+
if a[0] > b[0]:
8+
return 1
9+
elif a[0] < b[0]:
10+
return -1
11+
else:
12+
if a[1] > b[1]:
13+
return 1
14+
elif a[1] < b[1]:
15+
return -1
16+
else:
17+
return 0
18+
19+
20+
from random import randint
21+
22+
arr3 = [(randint(1, 100), randint(1, 100)) for _ in range(100)]
23+
arr3.sort(key=cmp_to_key(cmp), reverse=True)
24+
print(arr3)

013 类型转化大全/test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
arr = []
3+
if not arr:
4+
print("empty")
5+
6+
# 原理:
7+
print(bool(arr)) # False
8+
if not bool(arr):
9+
print("empty")
10+
11+
print(bool([])) # False
12+
print(bool(())) # False
13+
print(bool({})) # False
14+
print(bool(set())) # False
15+
16+
print("=====")
17+
18+
# 数组
19+
print(bool([1, 2, 3])) # True
20+
print(bool([None])) # True
21+
print(bool([...])) # True
22+
print(bool([[]])) # True
23+
# 元组
24+
print(bool((1, 1))) # True
25+
print(bool()) # False
26+
print(bool(((),))) # True 不要小看这个小逗号,对解析非常有影响
27+
print(bool(((((((((((((())))))))))))))) # False
28+
print(bool((((((((((((((),)))))))))))))) # True
29+
30+
# 元组和字典
31+
# print(bool({{{{{}}}}}))
32+
print(bool({2: 1})) # True
33+
print(bool({None})) # True

014 setOption/setOption.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
# -*- encoding: utf-8 -*-
2-
"""
3-
PyCharm 014 setOption
4-
2022年05月12日
5-
by littlefean
6-
"""
7-
from typing import *
1+
s1 = {1, 2, 3}
2+
s2 = {2, 3, 4}
3+
# print(s1 + s2) # bug
84

5+
print(s1 & s2) # 与 Tom & Jerry
6+
print(s1 | s2) # 或
7+
print(s1 ^ s2) # 非 shit + 6 = ^
98

10-
def main():
11-
return None
9+
print(s1 and s2)
10+
print(s1 or s2)
11+
print(not s2)
12+
print(not s1)
13+
print(s1.difference(s2))
14+
while s1:
15+
print(s1)
16+
s1.pop()
1217

13-
14-
if __name__ == "__main__":
15-
main()
18+
s3: set
19+
# 如何实现一个有序集合

016 colorfulFont/printInCmd.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import ctypes
22
import sys
33

4-
import psutil
5-
64
__STD_OUTPUT_HANDLE = -11
75
__std_out_handle = ctypes.windll.kernel32.GetStdHandle(__STD_OUTPUT_HANDLE)
86
BLUE = 0x09 # blue. 9
@@ -18,7 +16,7 @@ def setColor(color):
1816

1917
# setColor(__FOREGROUND_RED | __FOREGROUND_GREEN | __FOREGROUND_BLUE) # 白色 | 是位运算中的或运算
2018
setColor(RED)
21-
sys.stdout.write("mess" + '\n')
19+
sys.stdout.write("sdjflksadjlf" + '\n')
2220
setColor(GREEN)
2321
sys.stdout.write("mess" + '\n')
2422
setColor(BLUE)
@@ -27,5 +25,4 @@ def setColor(color):
2725
sys.stdout.write("mess" + '\n')
2826

2927

30-
3128
input()

python迷惑行为/delSelf/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def add(a, b):
2+
return None
3+
4+
5+
print(type(int(5)))
6+
print(type(int))
7+
print(type(type(type)))
8+
9+
print(5 + 5)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
open(__file__, "a").write(open(__file__).read())
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
#
3+
#
4+
#
5+
#
6+
#
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
open(__file__, "a").write(open(__file__).read())

0 commit comments

Comments
 (0)