动态参数
来源:互联网 发布:三洋微波炉怎么样知乎 编辑:程序博客网 时间:2024/05/18 12:30
动态参数
1.
def show(*arg): print(arg,type(arg))show(1,22,33,44)
(1, 22, 33, 44) <class 'tuple'> 转化为元组
2.
def show(**arg): print(arg,type(arg))show(n1=1,n2=22,n3=33,n4=44)
{'n1': 1, 'n2': 22, 'n3': 33, 'n4': 44} <class 'dict'> 转化为字典
3.
def show(*args,**kargs): print(args,type(args)) print(kargs, type(kargs))show(1,22,33,44,n1=55,k2=66)
(1, 22, 33, 44) <class 'tuple'> 转化为元组{'n1': 55, 'k2': 66} <class 'dict'> 转化为字典
4.
def show(*args,**kargs): print(args,type(args)) print(kargs, type(kargs))l = [1,22,33,44]d= {'n1':55,'k2':66}show(*l,**d)
(1, 22, 33, 44) <class 'tuple'> 转化为元组{'n1': 55, 'k2': 66} <class 'dict'> 转化为字典
使用动态参数实现字符串的格式化
1.
s = "{0} is {1}"result = s.format('dan','beautiful')print(result)
dan is beautiful
2.
l = ['dan','beautiful']result = s.format(*l)print(result)
dan is beautiful
3.
s = "{name} is {acter}"result = s.format(name='dan',acter='nice')print(result)
dan is nice
4.
d = {'name':'dan','acter':'nice'}result = s.format(**d)print(result)
dan is nice
阅读全文
0 0
- 动态参数
- 动态参数
- 动态参数
- 动态数组参数
- 动态语句返回参数
- OnClientClick动态参数绑定
- 动态参数查询
- 实现动态参数查询
- perl的动态参数
- Python的动态参数
- jdk动态参数
- 动态参数调用
- 存储过程动态参数
- 动态参数_Min
- struts2 动态传递参数
- 参数游标&动态游标
- 动态数组参数SetLength
- C语言动态参数
- iOS开发中动画之点赞图标放大效果
- Spring boot下配置使用redis--template编码形式
- 周末作业
- 作业5 oracle 安全管理
- markdown基础
- 动态参数
- solrCloud 在window上简单模拟搭建环境
- React笔记加报错
- 数据结构之串
- AttributeError: 'Bunch' object has no attribute 'data'
- 自然常数e
- 谈谈Spring中的IOC和AOP概念
- Photoshop抠图(磁性套索工具及几个常用案例)
- Java-算法分析及其优劣判断