All New

user:thomas gists created by user

title:mygist gists with given title

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

Login


All New Login

All gists matching topic function-arguments

Recently created
Least recently created
Recently updated
Least recently updated

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

0 likes
0 forks
2 files
Last active 8 months ago
一次搞懂 Python 函式參數打包與解包,*args 與 **kwargs 超簡單又靈活,從 list 和 dict 秒懂拆包魔法!
args function-arguments kwargs packing python tips unpacking
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

timmy / Python 參數解包 (*args 和 **kwargs)

0 likes
0 forks
1 files
Last active 10 months ago
這段 Python 程式碼 展示了 參數解包 (Argument Unpacking) 的應用方式,包括 列表解包 (*args) 和 字典解包 (**kwargs),用於函式呼叫時動態傳遞參數。
argument-unpacking assert dictionary-unpacking function-arguments list-unpacking python
1 assert list(range(3, 6)) == [3, 4, 5]
2
3 arguments_list = [3, 6]
4 assert list(range(*arguments_list)) == [3, 4, 5]
5
6
7 def function_that_receives_names_arguments(first_word, second_word):
8 return first_word + ", " + second_word + "!"
9
Newer Older

Powered by Opengist ⋅ Load: 39ms⋅

English
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文