Merge remote-tracking branch 'origin/master'

This commit is contained in:
2026-05-19 23:16:13 +08:00
18 changed files with 82 additions and 10 deletions
+10
View File
@@ -0,0 +1,10 @@
scope=input("请输入")
match scope:
case "1":
print("1")
case "2":
print("2")
case "3":
print("3")
case "4":
print("4")
+2
View File
@@ -0,0 +1,2 @@
for i in range(-1,100):
print(i)
-9
View File
@@ -1,9 +0,0 @@
# 自定义函数
def hehe(a,b,c):
print('hehe:'+a+b+c)
hehe('x','y','z')
def haha(a,b,c):
print('haha:'+a+b+c)
haha('x1','y1','z1')
+17
View File
@@ -0,0 +1,17 @@
# 自定义函数
def hehe(a,b,c):
print('hehe:'+a+b+c)
hehe('x','y','z')
#函数返回值
def haha(a,b,c):
"""
:param a:这是函数的文档1
:param b:这是函数的文档2
:param c:这是函数的文档3
:return: 这是函数的文档4
"""
return a+b+c
print("----")
print(haha(1,2,3))
+10
View File
@@ -0,0 +1,10 @@
def fun():
global a
a = 101
print(a)
# 函数正常调用
fun()
print('-------------')
#调用内部由global定义的变量
print(a)
+4
View File
@@ -0,0 +1,4 @@
# 简单加法
add =lambda x,y:x+y
print(add(100,200))
print("------")
+4
View File
@@ -0,0 +1,4 @@
# 与map在一块使用
numbers = [1,2,3,4]
a= list(map(lambda x:x*2,numbers))
print(a)
+3
View File
@@ -0,0 +1,3 @@
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a= list(filter(lambda x: x % 2 == 0, numbers))
print(a)
+4
View File
@@ -0,0 +1,4 @@
students = [('Alice', 85), ('Bob', 90), ('Charlie', 78)]
sorted_students = sorted(students, key=lambda x: x[1])
print(sorted_students)
# 按成绩排序: [('Charlie', 78), ('Alice', 85), ('Bob', 90)]
+16
View File
@@ -0,0 +1,16 @@
""""
nonlocal 是一个关键字
用于在嵌套函数(即内部函数)中修改外层函数(非全局作用域)中的变量。
"""
def fun1():
b = 100
def fun2():
nonlocal b
b = 300
print(b)
fun2()
print(b)
fun1()
print('----')
print(b)
+2 -1
View File
@@ -1,5 +1,6 @@
a=0 a=0
while a<10: while a<10:
if a<1: a+=1
if a<20:
print('xxx') print('xxx')
continue continue
+10
View File
@@ -0,0 +1,10 @@
"""
闭包函数
函数内部调用了函数外部的局部变量,并且外部函数返回内部函数即为闭包函数
"""
def func1():
a = 1001
def func2():
return a
return func2
print(func1()())