Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 46ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
p

packing

Recently created Least recently created Recently updated Least recently updated

timmy / 📦 拆包裝全都行!Python *args / **kwargs 超實用教學

Last active 5 hours ago args function-arguments kwargs packing python tips unpacking

一次搞懂 Python 函式參數打包與解包,*args 與 **kwargs 超簡單又靈活,從 list 和 dict 秒懂拆包魔法!

0 0 0 2
1 def func(*args):
2 for arg in args:
3 print(arg)
4
5 # Packing example:
6 func(1, 2, 3) # Output: 1 \n 2 \n 3
7
8 # Unpacking example:
9 my_list = [1, 2, 3]
10 func(*my_list) # Output: 1 \n 2 \n 3