# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#Python之str方法
#http://python.jobbole.com/82655/ #str为一个字符串,sub为str的一个子字符串。
#width为一个整数,用于说明新生成字符串的宽度。 #str.count(sub) 返回:sub在str中出现的次数
#str.find(sub) 返回:从左开始,查找sub在str中第一次出现的位置。如果str中不包含sub,返回 -1
#str.index(sub) 返回:从左开始,查找sub在str中第一次出现的位置。如果str中不包含sub,举出错误
#str.rfind(sub) 返回:从右开始,查找sub在str中第一次出现的位置。如果str中不包含sub,返回 -1
#str.rindex(sub) 返回:从右开始,查找sub在str中第一次出现的位置。如果str中不包含sub,举出错误 #str.isalnum() 返回:True, 如果所有的字符都是字母或数字
#str.isalpha() 返回:True,如果所有的字符都是字母
#str.isdigit() 返回:True,如果所有的字符都是数字
#str.istitle() 返回:True,如果所有的词的首字母都是大写
#str.isspace() 返回:True,如果所有的字符都是空格
#str.islower() 返回:True,如果所有的字符都是小写字母
#str.isupper() 返回:True,如果所有的字符都是大写字母 #str.split([sep, [max]]) 返回:从左开始,以空格为分割符(separator),将str分割为多个子字符串,总共分割max次。将所得的子字符串放在一个表中返回。可以str.split(‘,’)的方式使用逗号或者其它分割符
#str.rsplit([sep, [max]]) 返回:从右开始,以空格为分割符(separator),将str分割为多个子字符串,总共分割max次。将所得的子字符串放在一个表中返回。可以str.rsplit(‘,’)的方式使用逗号或者其它分割符 #str.join(s) 返回:将s中的元素,以str为分割符,合并成为一个字符串。
#str.strip([sub]) 返回:去掉字符串开头和结尾的空格。也可以提供参数sub,去掉位于字符串开头和结尾的sub
#str.replace(sub, new_sub) 返回:用一个新的字符串new_sub替换str中的sub
#str.capitalize() 返回:将str第一个字母大写
#str.lower() 返回:将str全部字母改为小写
#str.upper() 返回:将str全部字母改为大写
#str.swapcase() 返回:将str大写字母改为小写,小写改为大写
#str.title() 返回:将str的每个词(以空格分隔)的首字母大写 #str.center(width) 返回:长度为width的字符串,将原字符串放入该字符串中心,其它空余位置为空格。
#str.ljust(width) 返回:长度为width的字符串,将原字符串左对齐放入该字符串,其它空余位置为空格。
#str.rjust(width) 返回:长度为width的字符串,将原字符串右对齐放入该字符串,其它空余位置为空格。

Python之str方法的更多相关文章

  1. python的str,unicode对象的encode和decode方法

    python的str,unicode对象的encode和decode方法 python中的str对象其实就是"8-bit string" ,字节字符串,本质上类似java中的byt ...

  2. python str方法之ljust、rjust、center

    # -*- coding: cp936 -*- #python 27 #xiaodeng #str方法之ljust.rjust.center #http://www.runoob.com/python ...

  3. python的str,unicode对象的encode和decode方法(转)

    python的str,unicode对象的encode和decode方法(转) python的str,unicode对象的encode和decode方法 python中的str对象其实就是" ...

  4. python的str,unicode对象的encode和decode方法, Python中字符编码的总结和对比bytes和str

    python_2.x_unicode_to_str.py a = u"中文字符"; a.encode("GBK"); #打印: '\xd6\xd0\xce\xc ...

  5. Python 字典(Dictionary) str()方法

    Python 字典(Dictionary) str()方法 描述 Python 字典(Dictionary) str() 函数将值转化为适于人阅读的形式,以可打印的字符串表示.高佣联盟 www.cge ...

  6. python repr方法和str方法

    每个类都有默认的__repr__, __str__方法,用print 实例时调用类的str方法,直接输出类的实例,调用的是类的repr方法 在命令行界面,不用print命令打印而是直接写变量名,就是用 ...

  7. Python中sorted()方法

    Python中sorted()方法的用法 1.先说一下iterable,中文意思是迭代器. Python的帮助文档中对iterable的解释是:iteralbe指的是能够一次返回它的一个成员的对象.i ...

  8. python类及其方法

    python类及其方法 一.介绍 在 Python 中,面向对象编程主要有两个主题,就是类和类实例类与实例:类与实例相互关联着:类是对象的定义,而实例是"真正的实物",它存放了类中 ...

  9. python字符串replace()方法

    python字符串replace()方法 >>> help(str.replace)Help on method_descriptor:replace(...)    S.repla ...

随机推荐

  1. SQLServer2005中的CTE递归查询得到一棵树

    最近研究了一下CTE递归查询,感觉这个CTE递归查询蛮好用的,在网上找到了一个比较好的例子,测试例子如下 use City; go create table Tree ( ID ,) primary ...

  2. Oracle 11g 错误:ORA-28002: the password will expire within 7 days 解决方法

    ERROR:ORA-28002: the password will expire within 7 days 错误是提示password快过期了,有两个办法解决问题. 一. 改动已经报错用户的pas ...

  3. C#使用反射加载多个程序集

    当开发插件的时候需要用到反射,在客户端动态加载遍历程序集,并调用每个程序集的方法. 创建一个控制台应用程序,首先设计一个接口: public interface ISay { void SaySth( ...

  4. 03把IL编译成可执行文件

    1.在记事本中编写IL代码如下: .assembly HelloWorld{} .assembly extern mscorlib{}   .method public static void Mai ...

  5. C语言内存分析

    C语言内存分析 一.进制 概念:进制是一种计数方式,是数值的表现形式 4种主要的进制: ①. 十进制:0~9 ②. 二进制:0和1 ③. 八进制:0~7 ④. 十六进制:0~9+a b c d e f ...

  6. 【docker-compose】使用docker-compose启动spring-boot+mysql,服务内连数据库报错:create connection SQLException, url: jdbc:mysql://mysql:33061/swapping?useSSL=false&useUnicode=true&characterEncoding=UTF-8, errorCode 0,

    完整配置在这里, https://www.cnblogs.com/sxdcgaq8080/p/10070948.html 启动报错如下: 2018-12-05 01:04:05.569 ERROR 1 ...

  7. cocos2d-x avdrid 试例

    今天将cocos2d-x的示例项目tests编译到android真机运行,以及如何创建cocos2d-x的android项目. 打开cocos2d-x的tests项目,路径为:D:\cocos2d-x ...

  8. rman多通道全备份脚本

     run{ allocate channel d1 type disk; allocate channel d2 type disk; allocate channel d3 type disk; ...

  9. [翻译] 学习iOS开发的建议:如何从菜鸟到专家

    [文章原地址] http://mobile.tutsplus.com/tutorials/iphone/ios-quick-tip-from-novice-to-expert/ 翻译有误之处请勿见笑, ...

  10. JSON.parse()和JSON.stringify()方法

    parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...