zoukankan      html  css  js  c++  java
  • 格式化输出,深浅复制

    变量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=' ')

    • 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也不相同
  • 相关阅读:
    AS3中的xml
    HTML5 tools, Animation tools Adobe Edge Preview
    重新审视php+mssql
    SVN合并分支,从主干合并到分支
    AIR HTML相关资料[js部分]
    USACO 1.1friday
    H.High String
    POJ 3670 Eating Together
    HDU 1203:I NEED A OFFER!
    CodeForces #1 B. Spreadsheets
  • 原文地址:https://www.cnblogs.com/tangpg/p/7954049.html
Copyright © 2011-2022 走看看