|
发表于 2022-8-5 12:18:58
|
显示全部楼层
>>> a='连裤袜丝袜长筒袜'
>>> a.count(0,6)
Traceback (most recent call last):
File "<pyshell#332>", line 1, in <module>
a.count(0,6)
TypeError: must be str, not int
>>> a.count('袜',0,6)
2
>>> a='丝袜短袜小腿袜'
>>> a.count('袜',0,6)
2
>>> a.count('袜',0,7)
3
>>> a.find('袜')
1
>>> a.rfind('袜')
6
>>> a.find('1')
-1
>>> a.rfind('1')
-1
>>> a.index('1')
Traceback (most recent call last):
File "<pyshell#341>", line 1, in <module>
a.index('1')
ValueError: substring not found
>>> code='11111'
>>> code='11111'
>>> code='11111' print('22222')
SyntaxError: invalid syntax
>>> '111'.replace('111','2222')
'2222'
>>> t=str.maketrans('123456'='wxhnjz')
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
>>> t=str.maketrans('123456','wxhnjz')
>>> I love 123456.translate(t)
SyntaxError: invalid syntax
>>> 'I love 123456'.translate(t)
'I love wxhnjz'
>>> 'I believe 123456'.translate(t)
'I believe wxhnjz'
>>> 'I believe 123456'.translate(str.maketrans('123456','wxhnjz'))
'I believe wxhnjz'
>>> 'I believe 123456'.translate(str.maketrans('123456','wxhnjz'),'believe')
Traceback (most recent call last):
File "<pyshell#360>", line 1, in <module>
'I believe 123456'.translate(str.maketrans('123456','wxhnjz'),'believe')
TypeError: translate() takes exactly one argument (2 given)
>>> 'I believe 123456'.translate(str.maketrans('123456','wxhnjz','believe'))
'I wxhnjz'
>>> 'I believe 123456'.translate(str.maketrans('123456','wxhnjz','I believe'))
'wxhnjz'
>>> t
{49: 119, 50: 120, 51: 104, 52: 110, 53: 106, 54: 122}
>>> t=str.maketrans('123456','wxhnjz')
SyntaxError: unexpected indent
>>> t=str.maketrans('123456','wxhnjz')
>>> 'I believe 123456'.translate(t)
'I believe wxhnjz'
>>> 'I believe 123456'.translate(t)
'I believe wxhnjz'
>>> t=str.maketrans('123456','wxhnjz','I believe')
>>> 'I believe 123456'.translate(t)
'wxhnjz'
>>> x='我永远喜欢丝袜连裤袜小腿袜长筒袜连身袜全包丝袜'
>>> x.count('袜')
6
>>> x
'我永远喜欢丝袜连裤袜小腿袜长筒袜连身袜全包丝袜'
>>> x.index('袜')
6
>>> x.rindex('袜')
22
>>> x.find('袜')
6
>>> x.rfind('袜')
22 |
|