str文档
文档
class str(object):
"""
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str
---------------------------------------------------------------------
Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
将一个指定的对象转换为字符串形式,几根据一个指定的对象创建一个新的字符串对象。
另外,str(object)可以返回一个对象的信息说明,
如果没有,则会调用object对象的__str__()方法
如:print(str(print))的结果为:<built-in function print>
---------------------------------------------------------------------
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
""" def capitalize(self): # real signature unknown; restored from __doc__
"""
S.capitalize() -> str
---------------------------------------------------------------------
Return a capitalized version of S, i.e. make the first character
have upper case and the rest lower case.
将一个字符串首字母转换为大写,而且!而且其余字母全部转换为小写
如:'fuyong'.capitalize()与print('fuyong'.capitalize()的结果均为'Fuyong'
---------------------------------------------------------------------
"""
return "" def center(self, width, fillchar=None): # real signature unknown; restored from __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)
将字符串居中显示,可以指定总宽度以及填充值,默认用空格填充
如:print('fuyong'.center(20,'*'))的结果为:'*******fuyong*******'
---------------------------------------------------------------------
"""
return "" def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.count(sub[, start[, end]]) -> int
---------------------------------------------------------------------
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
返回一个子字符串在该字符串中出现的次数。参数start和end是可选参数,可以理解为是一个切片
---------------------------------------------------------------------
print('fuxiaoyong'.count('o')) # 2
print('fuxiaoyong'.count('o',6)) # 1
print('fuxiaoyong'.count('o',6,8)) # 1
---------------------------------------------------------------------
"""
return 0 def encode(self, encoding='utf-8', errors='strict'): # real signature unknown; restored from __doc__
"""
S.encode(encoding='utf-8', errors='strict') -> bytes
将一个字符串按照指定的编码方式编码成bytes类型,默认的编码格式为utf-8
---------------------------------------------------------------------
Encode S using the codec registered for encoding. Default encoding
is 'utf-8'. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
'xmlcharrefreplace' as well as any other name registered with
codecs.register_error that can handle UnicodeEncodeErrors.
"""
return b"" def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.endswith(suffix[, start[, end]]) -> bool
判断一个字符串是否以一个指定后缀结尾,返回一个布尔值
---------------------------------------------------------------------
Return True if S ends with the specified suffix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
suffix can also be a tuple of strings to try.
如果是以指定的后缀结尾,则返回True,否则返回False
start和end参数是可选参数。可以指定起始位置与结束位置,在此范围内进行判断,类似于切片的方式
后缀也可以是一个元组或者字符串,
如果是一个元组的话,后缀就在元组里选,任意一个元素满足返回True
---------------------------------------------------------------------
print('fuyong'.endswith('g')) # True
print('fuyong'.endswith('ong')) # True
print('fuyong'.endswith('ong',2)) # True
print('fuyong'.endswith('ong',1,3)) # False
print('fuyong'.endswith(('n','g'))) # True
print('fuyong'.endswith(('n','m'))) # False
---------------------------------------------------------------------
"""
return False def expandtabs(self, tabsize=8): # real signature unknown; restored from __doc__
"""
S.expandtabs(tabsize=8) -> str Return a copy of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
如果一个字符串中包括制表符'\t',那么可以用tabsize参数指定制表符的长度,
tabsize是可选的,默认值是8个字节
---------------------------------------------------------------------
print('fu\tyong'.expandtabs()) # 'fu yong'
print('fu\tyong'.expandtabs(4)) # 'fu yong'
---------------------------------------------------------------------
"""
return "" def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.find(sub[, start[, end]]) -> int
查找一个子字符串在原字符串中的位置,返回一个int类型的索引值
---------------------------------------------------------------------
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
如果在其中能找到(一个或多个)指定字符串,则返回最小索引值的那一个
意思是从左往右找,返回找到的第一个的索引值
也可以通过可选参数start和end来指定查找范围
---------------------------------------------------------------------
Return -1 on failure.
如果找不到,则返回 -1
---------------------------------------------------------------------
print('fuyong'.find('o')) # 3
print('fuyong is a old man'.find('o')) # 3
print('fuyong is a old man'.find('o',8)) # 12
print('fuyong is a old man'.find('o',5,8)) # -1
---------------------------------------------------------------------
"""
return 0 def format(self, *args, **kwargs): # known special case of str.format
"""
S.format(*args, **kwargs) -> str
格式化输出,返回一个str
---------------------------------------------------------------------
Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}').
格式化输出一段字符串。用{}的形式来占位
---------------------------------------------------------------------
=根据位置一一填充=
print('{}今年{}岁,{}是一个春心荡漾的年纪'.format('fuyong',18,18)) =根据索引对应填充=
print('{0}今年{1}岁,{1}是一个春心荡漾的年纪'.format('fuyong',18)) =根据关键字对应填充=
print('{name}今年{age}岁,{age}是一个春心荡漾的年纪'.format(name='fuyong',age=18)) =根据列表的索引填充=
num_list = [3,2,1]
print('列表的第二个数字是{lst[1]},第三个数字是{lst[2]}'.format(lst=num_list)) =根据字典的key填充=
info_dict = {'name':'fuyong','age':18}
print("他的姓名是{dic[name]},年纪是{dic[age]}".format(dic=info_dict)) =根据对象的属性名填充=
class Person:
def __init__(self,name,age):
self.name = name
self.age = age
print("他的姓名是{p.name},年纪是{p.age}".format(p=Person('fuyong',18)))
---------------------------------------------------------------------
"""
pass def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.index(sub[, start[, end]]) -> int
返回一个自字符串在原字符串的索引值
---------------------------------------------------------------------
Like S.find() but raise ValueError when the substring is not found.
跟find()函数类似,不同的是,如果找不到则会直接报错
---------------------------------------------------------------------
"""
return 0 def isalnum(self): # real signature unknown; restored from __doc__
"""
S.isalnum() -> bool Return True if all characters in S are alphanumeric
and there is at least one character in S, False otherwise.
判断一个字符串是不是全部由数字或者字母组成,返回一个布尔值
"""
return False def isalpha(self): # real signature unknown; restored from __doc__
"""
S.isalpha() -> bool Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.
判断一个字符串是不是全部由字母组成,返回一个布尔值
"""
return False def isdecimal(self): # real signature unknown; restored from __doc__
"""
S.isdecimal() -> bool Return True if there are only decimal characters in S,
False otherwise.
判断一个字符串是不是全部由十进制字符组成,返回一个布尔值
"""
return False def isdigit(self): # real signature unknown; restored from __doc__
"""
S.isdigit() -> bool Return True if all characters in S are digits
and there is at least one character in S, False otherwise.
判断一个字符串是不是全部由数字组成,返回一个布尔值
"""
return False def islower(self): # real signature unknown; restored from __doc__
"""
S.islower() -> bool Return True if all cased characters in S are lowercase and there is
at least one cased character in S, False otherwise.
判断一个字符串是否全部由小写字母组成,如果有任意一个字符为大写,则返回False
"""
return False def isspace(self): # real signature unknown; restored from __doc__
"""
S.isspace() -> bool Return True if all characters in S are whitespace
and there is at least one character in S, False otherwise.
判断一个字符串是否全部由空格字母组成
"""
return False def istitle(self): # real signature unknown; restored from __doc__
"""
S.istitle() -> bool Return True if S is a titlecased string and there is at least one
character in S, i.e. upper- and titlecase characters may only
follow uncased characters and lowercase characters only cased ones.
Return False otherwise.
"""
return False def isupper(self): # real signature unknown; restored from __doc__
"""
S.isupper() -> bool Return True if all cased characters in S are uppercase and there is
at least one cased character in S, False otherwise.
判断一个字符串是否全部由大写字母组成,如果有任意一个字符为小写,则返回False
"""
return False def join(self, iterable): # real signature unknown; restored from __doc__
"""
S.join(iterable) -> str Return a string which is the concatenation of the strings in the
iterable. The separator between elements is S.
将一个可迭代对象用指定字符串连接起来
返回值为一个字符串
"""
return "" def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
"""
S.ljust(width[, fillchar]) -> str Return S left-justified in a Unicode string of length width. Padding is
done using the specified fill character (default is a space).
以左为齐,将一个字符串的右!!右边填充指定字符串,可以指定宽度,默认为用空格填充。
不会改变原字符串,而会重新生成一个字符串 print('fuyong'.ljust(10,'*')) # fuyong****
"""
return "" def lower(self): # real signature unknown; restored from __doc__
"""
S.lower() -> str Return a copy of the string S converted to lowercase.
将一个字符串中的字符全部变为小写
"""
return "" def lstrip(self, chars=None): # real signature unknown; restored from __doc__
"""
S.lstrip([chars]) -> str Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
将一个字符串的从左边去掉指定的子字符串,默认为去空格
不会改变原字符串,而会重新生成一个字符串
"""
return "" def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
"""
S.replace(old, new[, count]) -> str Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
将字符串中的某一个子字符串替换为指定字符串
print('fuyong'.replace('yong','sir')) #fusir
"""
return "" def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.rfind(sub[, start[, end]]) -> int Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
与find方法类似,但是是从右边开始查找 Return -1 on failure.
如果找不到则返回 -1
"""
return 0 def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.rindex(sub[, start[, end]]) -> int Like S.rfind() but raise ValueError when the substring is not found.
与index方法类似,但是是从右边开始查找
如果找不到会直接报错
"""
return 0 def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
"""
S.rjust(width[, fillchar]) -> str Return S right-justified in a string of length width. Padding is
done using the specified fill character (default is a space).
以右为齐,将一个字符串的左!!左边填充指定字符串,可以指定宽度,默认为用空格填充。
print('fuyong'.rjust(10,'*')) # ****fuyong
"""
return "" def rsplit(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
"""
S.rsplit(sep=None, maxsplit=-1) -> list of strings Return a list of the words in S, using sep as the
delimiter string, starting at the end of the string and
working to the front. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified, any whitespace string
is a separator. """
return [] def rstrip(self, chars=None): # real signature unknown; restored from __doc__
"""
S.rstrip([chars]) -> str Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
将一个字符串的从右边去掉指定的子字符串,默认为去空格
不会改变原字符串,而会重新生成一个字符串
"""
return "" def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
"""
S.split(sep=None, maxsplit=-1) -> list of strings Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
将一个字符串以指定的子字符串进行分割,返回一个列表
如果找不到指定的子字符串,则会将原字符串直接放到一个列表中 print('fu.yong'.split('.')) # ['fu', 'yong']
print('fu.yong'.split('*')) # ['fu.yong']
"""
return [] def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.startswith(prefix[, start[, end]]) -> bool
判断一个字符串是否以一个指定字符串结尾,返回一个布尔值
---------------------------------------------------------------------
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try. 如果是以指定的字符串结尾,则返回True,否则返回False
start和end参数是可选参数。可以指定起始位置与结束位置,在此范围内进行判断,类似于切片的方式
后缀也可以是一个元组或者字符串,
如果是一个元组的话,后缀就在元组里选,任意一个元素满足返回True
"""
return False def strip(self, chars=None): # real signature unknown; restored from __doc__
"""
S.strip([chars]) -> str Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
去除左右两侧指定字符串,默认是去空格
"""
return "" def swapcase(self): # real signature unknown; restored from __doc__
"""
S.swapcase() -> str Return a copy of S with uppercase characters converted to lowercase
and vice versa.
将一个字符串的大小写反转
print('u.Yong'.swapcase()) # fU.yONG
"""
return "" def title(self): # real signature unknown; restored from __doc__
"""
S.title() -> str Return a titlecased version of S, i.e. words start with title case
characters, all remaining cased characters have lower case.
将一个字符串的!每个单词!首字母大写,并且,其他字母小写
注意与capitalize的却别
---------------------------------------------------------------------
print('fuYong'.capitalize()) #Fuyong
print('fu Yong'.capitalize()) #Fu yong
---------------------------------------------------------------------
print('fuYONG'.title()) # Fuyong
print('fu YONG'.title()) #Fu Yong
"""
return "" def upper(self): # real signature unknown; restored from __doc__
"""
S.upper() -> str Return a copy of S converted to uppercase.
将一个字符串的全部字符大写
"""
return "" def zfill(self, width): # real signature unknown; restored from __doc__
"""
S.zfill(width) -> str Pad a numeric string S with zeros on the left, to fill a field
of the specified width. The string S is never truncated.
将一个字符串按照指定宽度在左侧用0填充
注意,只填充左侧,而且只能用0填充
---------------------------------------------------------------------
print('fuyong'.zfill(10)) #0000fuyong
"""
return ""
示例
print('fuyong'.capitalize())
print('fuyong'.capitalize()) print('fuyong'.center(20,'*')) print('fuxiaoyong'.count('o'))
print('fuxiaoyong'.count('o',6))
print('fuxiaoyong'.count('o',6,8)) print('fuyong'.endswith('ong'))
print('fuyong'.endswith('ong',2))
print('fuyong'.endswith('ong',1,3))
print('fuyong'.endswith(('n','g')))
print('fuyong'.endswith(('n','g')))
print('fuyong'.endswith(('n','m'))) print('fu\tyong'.expandtabs())
print('fu\tyong'.expandtabs(4)) print('fuyong'.find('o'))
print('fuyong is a old man'.find('o'))
print('fuyong is a old man'.find('o',8))
print('fuyong is a old man'.find('o',5,8)) print('{}今年{}岁,{}是一个春心荡漾的年纪'.format('fuyong',18,18))
print('{0}今年{1}岁,{1}是一个春心荡漾的年纪'.format('fuyong',18))
print('{name}今年{age}岁,{age}是一个春心荡漾的年纪'.format(name='fuyong',age=18)) num_list = [3,2,1]
print('列表的第二个数字是{lst[1]},第三个数字是{lst[2]}'.format(lst=num_list)) info_dict = {'name':'fuyong','age':18}
print("他的姓名是{dic[name]},年纪是{dic[age]}".format(dic=info_dict)) class Person:
def __init__(self,name,age):
self.name = name
self.age = age
print("他的姓名是{p.name},年纪是{p.age}".format(p=Person('fuyong',18))) print('11'.isdecimal()) print('fuyong'.rjust(10,'*')) print('fuyong'.replace('yong','sir')) print('fu.yong'.split('.'))
print('fu.yong'.split('*')) print('fu.Yong'.swapcase()) print('fuYong'.capitalize())
print('fu Yong'.capitalize()) print('fuYONG'.title())
print('fu YONG'.title()) print('fuyong'.zfill(10))
str文档的更多相关文章
- ASP.NET Aries JSAPI 文档说明:AR.Utility
AR.Utility 文档 1:方法: 名称 说明 queryString function (key) *模拟.NET的Request对象 stringFormat function (str, a ...
- JSP实现word文档的上传,在线预览,下载
前两天帮同学实现在线预览word文档中的内容,而且需要提供可以下载的链接!在网上找了好久,都没有什么可行的方法,只得用最笨的方法来实现了.希望得到各位大神的指教.下面我就具体谈谈自己的实现过程,总结一 ...
- KOTLIN开发语言文档(官方文档) -- 入门
网页链接:https://kotlinlang.org/docs/reference/basic-syntax.html 1. 入门 1.1. 基本语法 1.1.1. 定义包 包说明应该在源 ...
- PHP执行文档操作
1.POWINTPOINT系列 之前参与过一个商城的项目,里面有将excel 导出的功能,但是如果要弄成PPT的我们应该怎么办呢?PHP是属于服务器端的 总不能在里面装个Powintpoint吧.于是 ...
- JAVA文档注释标签
1 常用Java注释标签(Java comment tags) @author 作者 @param 输入参数的名称 说明 @return 输出参数说明 @since JDK版本 @version ...
- Java POI 解析word文档
实现步骤: 1.poi实现word转html 2.模型化解析html 3.html转Map数组 Map数组(数组的操作处理不做说明) 1.导jar包. 2.代码实现 package com.web.o ...
- 关于WORD文档的读取乱码问题
一直以来都是用File类操作txt文档,今天想尝试能不能打开word文档,无奈,尝试了UTF8,Unicode,Default....等编码方式,打开文件都是乱码,电脑甚至发出警报声. 以下只取一种编 ...
- Seajs教程 配置文档
seajs.config Obj alias Obj 别名配置,配置之后可在模块中使用require调用require('jQuery'); seajs.config({ alias:{ 'jquer ...
- 解析txt文本,dom4j工具输出为xml文档
有如下一个ttl.txt文本文档,每一行用空格隔开的三段分别代表主谓宾, 要将它们输出为xml格式文档 工具:dom4j,jar包导入MyEclipse的Java Project工程 代码如下: pa ...
随机推荐
- 使用Navicat连接阿里云服务器上的MySQL数据库=======Linux 开放 /etc/hosts.allow
使用Navicat连接阿里云服务器上的MySQL数据库 1.首先打开Navicat,文件>新建连接> 2,两张连接方法 1>常规中输入数据库的主机名,端口,用户名,密码 这种直接 ...
- jQuery无刷新分页完整实例代码
在线演示地址如下: http://demo.jb51.net/js/2015/jquery-wsx-page-style-demo/ <!DOCTYPE html> <head> ...
- 数论 + 扩展欧几里得 - SGU 106. The equation
The equation Problem's Link Mean: 给你7个数,a,b,c,x1,x2,y1,y2.求满足a*x+b*y=-c的解x满足x1<=x<=x2,y满足y1< ...
- 三种CSS方法实现loadingh点点点的效果
我们在提交数据的时候,在开始提交数据与数据提交成功之间会有一段时间间隔,为了有更好的用户体验,我们可以在这个时间段添加一个那处点点点的动画,如下图所示: 汇总了一下实现这种效果主要有三种方法: 第一种 ...
- JDBC中,用于表示数据库连接的对象是。(选择1项)
JDBC中,用于表示数据库连接的对象是.(选择1项) A.Statement B.Connection C. DriverManager D.PreparedStatement 解答:B
- 【BZOJ】1637: [Usaco2007 Mar]Balanced Lineup(前缀和+差分+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1637 很神思想.. 前缀和应用到了极点... 我们可以发现当数量一定时,这个区间最前边的牛的前边一个 ...
- BEGIN_MESSAGE_MAP(Caccess_test_1Dlg, CDialogEx)
BEGIN_MESSAGE_MAP(...消息映射宏的一部分.ON_WM_CREATE()产生一个消息处理函数映射项目,把WM_CREATE和OnCreate函数联系起来. 参数的个数和类型是系统已经 ...
- java并发容器(Map、List、BlockingQueue)具体解释
Java库本身就有多种线程安全的容器和同步工具,当中同步容器包含两部分:一个是Vector和Hashtable.另外还有JDK1.2中增加的同步包装类.这些类都是由Collections.synchr ...
- Struts2_day01--导入源文件_Struts2的执行过程_查看源代码
导入源文件 选中按ctrl + shift + t进入 Struts2执行过程 画图分析过程 过滤器在服务器启动时创建,servlet在第一次访问时创建 查看源代码 public class Stru ...
- Maven手动添加dependency(以Oracle JDBC为例)
由于Oracle授权问题,Maven不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库.首先需要到Oracle官网上下载 ...