.Tang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

变量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  阅读(370)  评论(1编辑  收藏  举报