Files
Python_CookBook_repo/1.数据结构与算法/1.序列分解.py
2025-09-10 16:12:45 +08:00

14 lines
413 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 普通的序列分解方式
def normal_func(list):
# list是可迭代对象能够直接分解成多个元素
length = list.__len__()
length= 2
x, y = list
# 如果list长度和接数据的元素数量不匹配会造成错误
x, y, z = list
# 在知道元素顺序的情况下想要丢弃list中的某些元素可以用下划线来无视变量
_ ,y = list