拓冰建站拓冰建站
首页 / 资讯中心 / 正文

(Python基础教程之十五)Python开箱Tuple–太多值无法解压

Python示例,用于unpack元组或序列或可迭代,以便该元组可能长于N个元素,从而导致“太多的值无法unpack”异常。1.打开任意长度的元组Python“ star expressions”可用于unpack任意长度的元组。example1.py employee = ('Lokesh', 'email@example.com', '111-222-333', '444-555-666') name, email, *phone_numbers = employee name 'Lokesh' email 'email@example.com' phone_numbers ['111-222-333', '444-555-666'] example2.py *elements, end = [1,2,3,4,5,6,7,8] elements [1,2,3,4,5,6,7] end 82.unpack元组并丢弃不想要的值If there is a mismatch in the number of elements, you’ll get an error.example3.py recor
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门