python怎样定义一个变量从a到z_第三篇:python基础之数据类型与变量

classstr(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).

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."""

return ""

def casefold(self): #real signature unknown; restored from __doc__

"""S.casefold() -> str

Return a version of S suitable for caseless comparisons."""

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)"""

return ""

def count(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

"""从一个范围内的统计某str出现次数

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."""

return0def encode(self, encoding='utf-8', errors='strict'): #real signature unknown; restored from __doc__

"""encode(encoding='utf-8',errors='strict')

以encoding指定编码格式编码,如果出错默认报一个ValueError,除非errors指定的是

ignore或replace

S.encode(encoding='utf-8', errors='strict') -> bytes

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."""

returnFalsedef expandtabs(self, tabsize=8): #real signature unknown; restored from __doc__

"""将字符串中包含的\t转换成tabsize个空格

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."""

return ""

def find(self, sub, start=None, end=None): #real signature unknown; restored from __doc__

"""S.find(sub[, start[, end]]) -> 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.

Return -1 on failure."""

return0def format(self, *args, **kwargs): #known special case of str.format

"""格式化输出

三种形式:

形式一.

>>> print('{0}{1}{0}'.format('a','b'))

aba

形式二:(必须一一对应)

>>> print('{}{}{}'.format('a','b'))

Traceback (most recent call last):

File "", line 1, in

IndexError: tuple index out of range

>>> print('{}{}'.format('a','b'))

ab

形式三:

>>> print('{name} {age}'.format(age=12,name='lhf'))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值