string module

1. 進(jìn)入terminal輸入:python
2. 導(dǎo)入string module :import string
3. 顯示string module中的所有方法: dir(string)
4. 查看string中的某個(gè)方法怎么使用:help(string.方法名),按q退出
GrandKai:~ GrandKai$ python3
Python 3.5.2 (default, Oct 14 2016, 15:01:45) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> dir(string)
['Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_float', '_idmap', '_idmapL', '_int', '_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']
>>>help(string.Formatter)

string中幾個(gè)常用的方法

string.atof(s)# Convert to float  
string.atoi(s)# Convert to integer
string.atol(s)# Convert to long
string.count(s,pattern)# Count occurrences of pattern in s
string.find(s,pattern)# Find pattern in s
string.split(s, sep)# String a string
string.join(strlist, sep)  # Join a list of string
string.replace(s,old,new)  # Replace occurrences of old with new
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評(píng)論 19 139
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,679評(píng)論 18 399
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,027評(píng)論 25 709
  • 之前有一句很流行的話,叫誰的青春不迷茫,我和你們一樣,曾經(jīng)都被這句話騙的暈頭轉(zhuǎn)向。 1 趙本山女兒妞妞最近被頂在了...
    微風(fēng)清酒閱讀 548評(píng)論 0 19
  • 只有讀書才能知道自己有多無知啊。 越讀書越知道天外有天,人外有人,人才不會(huì)不知道天高地厚。 最近一段時(shí)間想在簡書上...
    王麗燕199閱讀 688評(píng)論 0 3

友情鏈接更多精彩內(nèi)容