python简单练习
>>> str1='I love xixi'>>> str[:6]
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
str[:6]
TypeError: 'type' object is not subscriptable
>>> str1[:6]
'I love'
>>> str1
'e'
>>> str1[:6]+'haha'+str1
'I lovehaha xixi'
>>> str1[:6]+' haha'+str1
'I love haha xixi'
>>> str1=str1[:6]+'haha'+str1
>>> str1
'I lovehaha xixi'
>>> str1='hzuxw'
>>> str1.capitalize()
'Hzuxw'
>>> str2='HELLO'
>>> str2.casefold()
'hello'
>>> str2
'HELLO'
>>> str2.center(20)
' HELLO '
>>> str2.count(E)
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
str2.count(E)
NameError: name 'E' is not defined
>>> str2.count('E')
1
>>> str2.endswith('O')
True
>>> str3='I\love\you'
>>> str3.expandtabs(20)
'I\\love\\you'
>>> str3.expandtabs(8)
'I\\love\\you'
>>> str3.find('ELL')
-1
>>> str4='Love'
>>> str4.istitle()
True
>>> str4.join('haha')
'hLoveaLovehLovea'
>>> str4.split()
['Love']
>>> str5=' sssaaasssaa '
>>> str5.strip()
'sssaaasssaa'
>>> str5
' sssaaasssaa '
>>> str6=str5.strip('s')
>>> str6
' sssaaasssaa '
>>> str6.translate(str.maketrans('s','b'))
' bbbaaabbbaa '
>>> str.maketrans('s','b')
{115: 98}
>>> '{0} love {1},{2}'.format('i','fishc','com')
'i love fishc,com'
>>>'{a} love {b},{c}'.format(a='i',b='fishc',c='com')
SyntaxError: unexpected indent
>>>"{a} love {b},{c}".format(a='i',b='fishc',c='com')
SyntaxError: unexpected indent
>>>"{a} love {b},{c}".format(a="i",b="fishc",c="com")
SyntaxError: unexpected indent
>>> '{0} love {1},{2}'.format('i','fishc','com')
'i love fishc,com'
>>> what? goodboy2019 发表于 2019-4-9 18:14
what?
啥意思。。。
页:
[1]