python end of statement_python 笔记

字符串>>> 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'

>>>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值