python--一些mark

来源:互联网 发布:儿童学编程网 编辑:程序博客网 时间:2024/05/16 05:09
 str = 'wo xihuan python '
>>> str
'wo xihuan python '
>>> str2 = str[3:6] + 'cha ru de ' + str[7:]
>>> str2
'xihcha ru de an python '

>>>


>>> "{0} love {1}".format("U",'me')
'U love me'
>>> "{a} love {b}".format(a="U",b='me')
'U love me'
>>> "{0:.1f}{1}".format(27.658,'GB')
'27.7GB'
>>> '%d + %d =%d' % (4,5,4+5)
'4 + 5 =9'
>>>



>>> b = 'wo xi huan daota'
>>> a = list(b)
>>> a
['w', 'o', ' ', 'x', 'i', ' ', 'h', 'u', 'a', 'n', ' ', 'd', 'a', 'o', 't', 'a']
>>> len(a)
16
>>> max(a)
'x'
>>> mix(a)
Traceback (most recent call last):
  File "<pyshell#230>", line 1, in <module>
    mix(a)
TypeError: 'list' object is not callable
>>> min(a)
' '
>>> tu = (1,2,3,4,5,6)
>>> max(tu)
6
>>> 6
6
>>> tu.append('a')
Traceback (most recent call last):
  File "<pyshell#235>", line 1, in <module>
    tu.append('a')
AttributeError: 'tuple' object has no attribute 'append'
>>> tu.append('a')
Traceback (most recent call last):
  File "<pyshell#236>", line 1, in <module>
    tu.append('a')
AttributeError: 'tuple' object has no attribute 'append'
>>> sum(tu)
21
>>> sum(tu,8)
29
>>> sorted(tu)
[1, 2, 3, 4, 5, 6]
>>> sorted(tu)
[1, 2, 3, 4, 5, 6]
>>> a = [1,2,3,4]
>>> b = [2,3,4,5,6,]
>>> zip(a,b)
<zip object at 0x02DB2170>
>>> zip(b,a)
<zip object at 0x02DB2300>
>>> list(zip(a,b))
[(1, 2), (2, 3), (3, 4), (4, 5)]
>>>


0 0
原创粉丝点击