字符串>>> print ("hello"*3)
hellohellohello>>> print ("helloworld"[2:4])
ll>>> print ("or" in "helloworld")
True>>> print ("%s is a good man" %"gtms")
gtmsisa good man>>> print ("a","b")
a b>>> print ("a"+"b") ==〉会开辟2个内存块,一般不用加号拼
ab>>> print ("a"-"b")
Traceback (most recent call last):
File"", line 1, in TypeError: unsupported operand type(s)for -: 'str' and 'str'[root@node206 code]# cat test.py
print ("hello world",end=" ")
print ("hello world")
[root@node206 code]# python3 test.py
hello world hello world>>> a="gtms"
>>> b="is"
>>> c="a"
>>> d="man"
>>> print (a+b+c+d)
gtmsisaman>>> e="".join([a,b,c,d])
>>> e'gtmsisaman'
>>> e="**".join([a,b,c,d])>>>e'gtms**is**a**man'
>>> e="/".join([a,b,c,d])
>>> e'gtms/is/a/man'内置方法>>> st="hello kitty"
>>> st.count("l")2
>>> st.capitalize()'Hello kitty'
>>>st.center()
Traceback (most recent call last):
File"", line 1, in TypeError: center() takes at least1 argument (0given)>>> st.center(50,"-")'-------------------hello kitty--------------------'
>>> st.endwith("tty")
Traceback (most recent call last):
File"", line 1, in AttributeError:'str' object has no attribute 'endwith'
>>> st.endswith("tty")
True>>> st.startwith("he")
Traceback (most recent call last):
File"", line 1, in AttributeError:'str' object has no attribute 'startwith'
>>> st.startswith("he")
True>>> sst="hello k\titty"
>>> sst.expandtabs(tabsize=10)'hello k itty'
>>>st.find(t)
Traceback (most recent call last):
File"", line 1, in NameError: name't' isnot defined>>> st.find("t")8
>>> st.find("tt")8
>>> st.find("ty")9
>>> sst="hello titty {name}"
>>> st.format(name="gtms")'hello kitty'
>>> sst.find("ty")9
>>> print (sst.format(name="gtms")
... )
hello titty gtms>>> sst="hello titty {name} {age}"
>>> sst.format(name="gtms",age-36)
File"", line 1SyntaxError: positional argument follows keyword argument>>> sst.format(name="gtms",age=36)'hello titty gtms 36'
>>> sst.format_map({"name":"gtms","age"=36})
File"", line 1sst.format_map({"name":"gtms","age"=36})^SyntaxError: invalid syntax>>> sst.format_map({"name":"gtms","age":36})'hello titty gtms 36'
>>>sst'hello titty {name} {age}'
>>> st.index("ty")9
>>>st.isalnum()
False>>> "aaa".isalnum()
True>>> "aaa".isdecimal()
False>>> "666".isdecimal()
True>>> "0101".isdecimal()
True>>> "0101".isdigit()
True>>> "125.66".isdigit()
False>>> "0101".isnumber()
Traceback (most recent call last):
File"", line 1, in AttributeError:'str' object has no attribute 'isnumber'
>>> "0101".isnumeric()
True>>> "123".isidentifier()
False>>> "abc".isidentifier()
True>>> "aBc".islower()
False>>> "aBc".isupper()
False>>> "ABc".isupper()
False>>> "ABc c".isspace()
False>>> " ".isspace()
True>>> "".isspace()
False>>> "ABc c".istitle()
False>>> "ABc C".istitle()
False>>> "Ac C".istitle()
True>>> "Ac C".lower()'ac c'
>>> "Ac C".upper()'AC C'
>>> "Ac C".swapcase()'aC c'
>>> "Ac C".ljust(50,“?”)
File"", line 1
"Ac C".ljust(50,“*”)^SyntaxError: invalid characterinidentifier>>> "Ac C".ljust(50,"*")
File"", line 1
"Ac C".ljus,"*")^SyntaxError: invalid syntax>>> "Ac C".ljust(50,"*"File"", line 1
"Ac C".ljust(50"*"
^SyntaxError: invalid syntax>>> "Ac C".ljust(50,"*"... )'Ac C**********************************************'
>>> "Ac C".rjust(50,"*")'**********************************************Ac C'
>>> "Ac C".str(50,"*")
Traceback (most recent call last):
File"", line 1, in AttributeError:'str' object has no attribute 'str'
>>> "Ac C".strip()'Ac C'
>>> "\tAc C\n".strip()'Ac C'
>>> "\tAc C\n".lstrip()'Ac C\n'
>>> "\tAc C\n".rstrip()'\tAc C'
>>>