|
In [2]: s = "I love python"
In [3]: s.upper()
Out[3]: 'I LOVE PYTHON'
In [5]: s.lower()
Out[5]: 'i love python'
In [6]: s.title() # 首字母全部大写
Out[6]: 'I Love Python'
In [8]: s.capitalize() # 把首字母大写
Out[8]: 'I love python'
In [10]: print(s.center.__doc__) # 在给定宽度下居中,可以使用单个字符填充
S.center(width[, fillchar]) -> str
Return S centered in a string of length width. Padding is
done using the specified fill character (default is a space)
In [11]: s.center(50)
Out[11]: ' I love python '
In [12]: s.center(50, "#")
Out[12]: '##################I love python###################'
In [13]: s.center(50, "#%")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-4aa39ce1c3b3> in <module>()
----> 1 s.center(50, "#%")
TypeError: The fill character must be exactly one character long
In [19]: s
Out[19]: 'I love python'
In [20]: s.zfill(5)
Out[20]: 'I love python'
In [21]: s.zfill(50) # 用0填充
Out[21]: '0000000000000000000000000000000000000I love python'
In [23]: print(s.casefold.__doc__)
S.casefold() -> str
Return a version of S suitable for caseless comparisons.
In [25]: s
Out[25]: 'I love python'
In [26]: s.casefold() # 返回一个统一大小写的str,在不同平台有不同的表现形式
Out[26]: 'i love python'
In [27]: s.swapcase() # 交换大小写
Out[27]: 'i LOVE PYTHON'
In [36]: "\t".expandtabs() # 默认将\t转换为8个空格
Out[36]: ' '
In [40]: "\t".expandtabs(8)
Out[40]: ' '
In [37]: "\t".expandtabs(3)
Out[37]: ' ' |
|
|