Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand args and kwargs

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to understand args and kwargs, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, people who have this need can learn, I hope you can gain something.

*args and **kwargs.

#Fixed parameters #Fixed parameters, variable parameters args, default parameters, variable parameters kwargs def foo(name,*args,flag=True,**kwargs):

print(name,args) print("=========")

print(kwargs) print("========")

print(flag)if __name__ == '__main__':

print(*(1,2,3,4,45))

#foo("Zhang San",1,2,3,45,flag=False,id=123,password="1234qwer")

foo("Zhang San",*(1,2,3,45),flag=1234,**{"id":123,"password":"1234qwer"})

Results after running:

1 2 3 4 45 sheets three (1, 2, 3, 45)======={'id': 123, 'password': '1234 qwer'}========1234[Finished in 0.0s] Is it helpful to read the above? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 292

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report