string module

1. 进入terminal输入:python
2. 导入string module :import string
3. 显示string module中的所有方法: dir(string)
4. 查看string中的某个方法怎么使用: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中几个常用的方法

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,269评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,839评论 18 399
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,615评论 25 709
  • 之前有一句很流行的话,叫谁的青春不迷茫,我和你们一样,曾经都被这句话骗的晕头转向。 1 赵本山女儿妞妞最近被顶在了...
    微风清酒阅读 496评论 0 19
  • 只有读书才能知道自己有多无知啊。 越读书越知道天外有天,人外有人,人才不会不知道天高地厚。 最近一段时间想在简书上...
    王丽燕199阅读 635评论 0 3