您的位置:首页 > 编程语言 > Python开发

python中的string模块

2016-03-20 20:40 549 查看
DESCRIPTION

Warning: most of the code you see here isn't normally used nowadays.

Beginning with Python 1.6, many of these functions are implemented as

methods on the standard string object. They used to be implemented by

a built-in module called strop, but strop is now obsolete itself.

Public module variables:

whitespace -- a string containing all characters considered whitespace

lowercase -- a string containing all characters considered lowercase letters

uppercase -- a string containing all characters considered uppercase letters

letters -- a string containing all characters considered letters

digits -- a string containing all characters considered decimal digits

hexdigits -- a string containing all characters considered hexadecimal digits

octdigits -- a string containing all characters considered octal digits

punctuation -- a string containing all characters considered punctuation

printable -- a string containing all characters considered printable

大多数代码你现在看到的不是通常使用。

从Python 1.6开始,许多这些功能实现的

方法标准字符串对象。他们使用来实现

一个内置的模块称为磨,但磨现在过时了。

公共模块变量:

空白——一个字符串包含所有字符空格

小写,包含所有字符的字符串小写字母

大写——一个字符串包含所有字符大写字母

字母——一个字符串包含所有字符是字母

数字——一个字符串包含所有字符视为小数位数

hexdigits——一个字符串包含所有字符视为十六进制数字

octdigits——一个字符串包含所有字符视为八进制数字

标点符号——一个字符串包含所有字符标点符号

可打印——一个包含所有字符视为可打印字符串

CLASSES

__builtin__.object

Formatter

Template

class Formatter(__builtin__.object)

| Methods defined here:

|

| check_unused_args(self, used_args, args, kwargs)

|

| convert_field(self, value, conversion)

|

| format(*args, **kwargs)

|

| format_field(self, value, format_spec)

|

| get_field(self, field_name, args, kwargs)

| # given a field_name, find the object it references.

| # field_name: the field being looked up, e.g. "0.name"

| # or "lookup[3]"

| # used_args: a set of which args have been used

| # args, kwargs: as passed in to vformat

|

| get_value(self, key, args, kwargs)

|

| parse(self, format_string)

| # returns an iterable that contains tuples of the form:

| # (literal_text, field_name, format_spec, conversion)

| # literal_text can be zero length

| # field_name can be None, in which case there's no

| # object to format and output

| # if field_name is not None, it is looked up, formatted

| # with format_spec and conversion and then used

|

| vformat(self, format_string, args, kwargs)

|

| ----------------------------------------------------------------------

| Data descriptors defined here:

|

| __dict__

| dictionary for instance variables (if defined)

|

| __weakref__

| list of weak references to the object (if defined)

class Template(__builtin__.object)

| A string class for supporting $-substitutions.

|

| Methods defined here:

|

| __init__(self, template)

|

| safe_substitute(*args, **kws)

|

| substitute(*args, **kws)

|

| ----------------------------------------------------------------------

| Data descriptors defined here:

|

| __dict__

| dictionary for instance variables (if defined)

|

| __weakref__

| list of weak references to the object (if defined)

|

| ----------------------------------------------------------------------

| Data and other attributes defined here:

|

| __metaclass__ = <class 'string._TemplateMetaclass'>

|

|

| delimiter = '$'

|

| idpattern = '[_a-z][_a-z0-9]*'

|

| pattern = <_sre.SRE_Pattern object>



__builtin__.object

格式化程序

模板

Formatter类(__builtin__.object)

|这里定义方法:

|

| check_unused_args(自我、used_args args,kwargs)

|

| convert_field(自我价值,转换)

|

|格式(* args,* * kwargs)

|

| format_field(自我价值,format_spec)

|

| get_field(自我、field_name args,kwargs)

| # field_name,找到它引用的对象。

| # field_name:字段被抬起头,如。“0.名称”

| #或“查找”[3]

| # used_args:一组使用arg游戏

| # args,kwargs:vformat传入

|

FUNCTIONS

atof(s)

atof(s) -> float

Return the floating point number represented by the string
s.

atoi(s, base=10)

atoi(s [,base]) -> int

Return the integer represented by the string
s in the given

base, which defaults to 10. The
string s must consist of one

or more digits, possibly preceded by a sign. If
base is 0, it

is chosen from the leading characters of s, 0 for octal,
0x or

0X for hexadecimal. If
base is 16, a preceding 0x or 0X is

accepted.

atol(s, base=10)

atol(s [,base]) -> long

Return the long integer represented by the
string s in the

given base, which defaults to 10. The
string s must consist

of one or more digits, possibly preceded by a sign. If
base

功能

atof(s)

atof(s)- >浮动

返回浮点数表示的字符串。

atoi(年代,基地= 10)

atoi(s[,])- > int

返回整数代表的字符串在给定的

基地,默认为10。字符串必须包含一个

或更多的数字,可能之前签署。如果基本为0,它

选择主要人物的年代,0为八进制,0 x或

0 x十六进制。如果基地16个,前的0
x 0 x

接受。

atol(年代,基地= 10)

atol(s[,])- >长

返回所表示的长整数字符串中

鉴于基地,默认为10。字符串必须由

一个或多个数字,可能之前的迹象。如果基础

If
base

is 0, it is chosen from the leading characters of s, 0 for

octal, 0x or 0X for hexadecimal. If base is 16, a preceding

0x or 0X is accepted. A trailing L or l is not accepted,

unless base is 0.

capitalize(s)

capitalize(s) -> string

Return a copy of the string s with only its first character

capitalized.

capwords(s, sep=None)

capwords(s [,sep]) -> string

Split the argument into words using split, capitalize each

word using capitalize, and join the capitalized words using

join. If the optional second argument sep is absent or None,

runs of whitespace characters are replaced by a single space

and leading and trailing whitespace are removed, otherwise

sep is used to split and join the words.

center(s, width, *args)

center(s, width[, fillchar]) -> string

Return a center version of s, in a field of the specified

width. padded with spaces as needed. The string is never

truncated. If specified the fillchar is used instead of spaces.

count(s, *args)

count(s, sub[, start[,end]]) -> int

Return the number of occurrences of substring sub in string

s[start:end]. Optional arguments start and end are

interpreted as in slice notation.

expandtabs(s, tabsize=8)

expandtabs(s [,tabsize]) -> string

Return a copy of the string s with all tab characters replaced

by the appropriate number of spaces, depending on the current

column, and the tabsize (default 8).

如果基础

是0,这是选择从年代的主要人物,0

八进制,0 x或者x十六进制。如果基地16日之前

0 x或者x是接受。落后于L或L不接受,

除非基地是0。

大写(s)

大写(s)- >字符串

返回字符串的副本年代只有它的第一个字符

大写。

capwords(年代,9 =没有)

capwords(s[9])- >字符串

将参数分为单词使用分割,利用

使用大写单词,并加入大写单词使用

加入。如果9月可选的第二个参数是缺失或没有,

空白字符替换为一个空格

和前导和尾随空白被删除,否则

9月是用来分割并加入的话。

中心(年代,宽度,* args)

中心(年代,宽度[,fillchar])- >字符串

返回一个中心版本的年代,在一个指定的领域

宽度。根据需要填充的空间。字符串是从来没有

截断。如果指定了fillchar代替空间。

数(年代,* args)

计数(年代,子,开始[,]])- > int

返回的数量出现的子字符串的子字符串

年代开始:结束。可选参数的开始和结束

解释为片符号。

expandtabs(年代,tabsize = 8)

expandtabs(s[,tabsize])- >字符串

返回字符串的副本与所有制表符替换

由适当数量的空间,根据当前

列,tabsize(默认8)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: