|
发表于 2024-2-29 10:33:02
|
显示全部楼层
Python 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:15:12) [MSC v.1937 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
x = "123321"
"是回文数字" if x == x[::-1] else "不是回文数字"
'是回文数字'
x = "123456789"
"是回文数字" if x == x[::-1] else "不是回文数字"
'不是回文数字'
x = "what are you doing now?"
x.capitalize()
'What are you doing now?'
x.casefold()
'what are you doing now?'
x.title()
'What Are You Doing Now?'
x.swapcase()
'WHAT ARE YOU DOING NOW?'
x.upper()
'WHAT ARE YOU DOING NOW?'
x.lower ()
'what are you doing now?'
x.center()
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
x.center()
TypeError: center expected at least 1 argument, got 0
x.center(5)
'what are you doing now?'
x.center(15)
'what are you doing now?'
x="我的妈呀,快跑"
x.center(5)
'我的妈呀,快跑'
x.center(15)
' 我的妈呀,快跑 '
x.rjust()
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
x.rjust()
TypeError: rjust expected at least 1 argument, got 0
x.rjust(5)
'我的妈呀,快跑'
x.rjust(15)
' 我的妈呀,快跑'
x.ljust(15)
'我的妈呀,快跑 '
x.zfill(15)
'00000000我的妈呀,快跑'
'00000000我的妈呀,快跑'
'00000000我的妈呀,快跑'
x.ljust(14,"啊")
'我的妈呀,快跑啊啊啊啊啊啊啊'
x.rjust(14,"啊")
'啊啊啊啊啊啊啊我的妈呀,快跑'
x.center(14,"啊")
SyntaxError: invalid character ')' (U+FF09)
x.center(14,"啊")
'啊啊啊我的妈呀,快跑啊啊啊啊'
|
|