格式化输出,深浅复制

变量3个属性:

  • a=1   值,地址id(a),类型type(a)

list,str,tuple,dict等类型,自带的方法可用dir()查看

  • complex复数
  • >>> complex(1)
  • (1+0j)
  • >>> complex(1,2)
  • (1+2j)

格式化输出:

  • s='hello'
  • t='python'
  • r='!'
  • print(s+t+r)
  • print('%s%s%s'%(s,t,r))
  • >>>输出结果为
  • hellopython!
  • hellopython!
  • format
  • print('{}{}{}'.format(s,t,r))
  • print('{a}{b}{c}'.format(a=s,b=t,c=r))
  • print('{:^10}'.format('hello')) #居中             hello                 居中
    print('{:*^10}'.format(a))                  #      **hello***              居中两边以 * 填充
    print('{:*<10}'.format(a))#左                   hello*****              
    print('{:*>10}'.format(a)) #right              *****hello

  • >>>
  • hellopython!
  • hellopython!
  • print(''.join(s+t+r))
    print('..'.join(s+t+r))

  • >>>
  • hellopython!
  • h..e..l..l..o..p..y..t..h..o..n..!

print函数默认参数为:

print(sep=' ',end='\n')

  • print('',1,'',sep='****')  #将sep的值给  ''   --->>    ****1****
  • print(1,end='flower')  #输出类容以什么结尾  --->>    1flower

深浅复制区别:

li=[1,2,[3,4,5]]

*li里面每一个元素都是有一个id

  • 浅复制copy
  • li1=li.copy()
  • li1里的子列表[3,4,5]的 id与 li 的子列表[3,4,5]相同,如果你改变li1子列表的值,li也会跟着改变

深复制deepcopy

  • import copy
  • li2=copy.deepcopy(li)
  • li2里的子列表[3,4,5]的 id与 li 的子列表[3,4,5]不同,如果你改变li2子列表的值,li却不会跟着改变
  • 当然li,li1,li2的id也不相同
posted on 2017-12-02 13:41 .Tang 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/tangpg/p/7954049.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值