python 字符串
2020-12-13 03:31
标签:uid slow attr api 操作方法 串操作 字符 str ack key point: 字符串都是不可改变的 打印: >>> values >>> ‘%s plus %s equals %s‘ % (1, 1, 2) >>> ‘Using str %r‘ % 42 >>> ‘Using str %r‘ % 42 >>> ‘%010.2f‘ % pi 字符串操作方法:find >>> title = "Monty Python‘s Flying Circus" 字符串操作方法:join >>> ‘+‘.join([‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘]) 字符串操作方法: lower title capitalize swapcase >>> ‘test‘.islower() 字符串操作方法:replace >>> ‘THis is a test‘.replace(‘is‘,‘eez‘) 字符串操作方法: split >>> ‘1+2+3+4+5‘.split(‘+‘) 字符串操作方法:strip() >>> ‘ pan is pan ‘.strip() 字符串操作方法:translate python3.7 not support python 字符串 标签:uid slow attr api 操作方法 串操作 字符 str ack 原文地址:https://www.cnblogs.com/lianghong881018/p/11077617.html
(‘world‘, ‘hot‘)
>>> format
‘hello, %s. %s enough for ya‘
>>> print(format % values)
hello, world. hot enough for ya
‘1 plus 1 equals 2‘
‘Using str 42‘
‘Using str 42‘
>>> ‘%10f‘ %pi
‘ 3.141593‘
>>> ‘%10.2f‘ % pi
‘ 3.14‘
>>> ‘%.2f‘ % pi
‘3.14‘
>>> ‘%.5s‘ % ‘Guido van rossum‘
‘Guido‘
‘0000003.14‘
>>> title.find(‘Python‘)
6
‘1+2+3+4+5‘
>>> dirs = ‘‘, ‘usr‘,‘bin‘,‘env‘
>>> ‘/‘.join(dirs)
‘/usr/bin/env‘
True
>>> ‘test‘.titla()
Traceback (most recent call last):
File "", line 1, in
AttributeError: ‘str‘ object has no attribute ‘titla‘
>>> ‘test‘.title()
‘Test‘
>>> ‘test‘.capitalize()
‘Test‘
>>> ‘test‘.swapcase()
‘TEST‘
‘THeez eez a test‘
[‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘]
‘pan is pan‘
下一篇:popup window