閱讀360 返回首頁    go 阿裏雲 go 技術社區[雲棲]


python字符串(2)

首先Python中的字符串對象依賴於str類,類裏麵包含了我們多使用到的所有方法,代碼詳見如下:
class str(basestring):
    """String object."""

    def __init__(self, object=''):
        """Construct an immutable string.#構造一個不可變的字符串,初始化對象使用

        :type object: object
        """
        pass

    def __add__(self, y):
        """The concatenation of x and y.#連接x和y  x,y均為字符串類型

        :type y: string
        :rtype: string
        """
        return b''

    def __mul__(self, n):
        """n shallow copies of x concatenated.#n淺層副本x連接。就是字符串的n倍出現連接
:type n: numbers.Integral :rtype: str """ return b'' def __mod__(self, y): #求餘 """x % y. :rtype: string """ return b'' def __rmul__(self, n): """n shallow copies of x concatenated.#n淺層副本x連接。就是字符串的n倍出現連接
:type n: numbers.Integral :rtype: str """ return b'' def __getitem__(self, y): """y-th item of x, origin 0. #實現類似slice的切片功能 :type y: numbers.Integral :rtype: str """ return b'' def __iter__(self): #迭代器 """Iterator over bytes. :rtype: collections.Iterator[str] """ return [] def capitalize(self): """Return a copy of the string with its first character capitalized #實現首字母大寫 and the rest lowercased. :rtype: str """ return b'' def center(self, width, fillchar=' '): #中間對齊 """Return centered in a string of length width. :type width: numbers.Integral :type fillchar: str :rtype: str """ return b'' def count(self, sub, start=None, end=None): #計算字符在字符串中出現的次數 """Return the number of non-overlapping occurrences of substring sub in the range [start, end]. :type sub: string :type start: numbers.Integral | None :type end: numbers.Integral | None :rtype: int """ return 0 def decode(self, encoding='utf-8', errors='strict'): #把字符串轉成Unicode對象 """Return a string decoded from the given bytes. :type encoding: string :type errors: string :rtype: unicode """ return '' def encode(self, encoding='utf-8', errors='strict'):#轉換成指定編碼的字符串對象 """Return an encoded version of the string as a bytes object. :type encoding: string :type errors: string :rtype: str """ return b'' def endswith(self, suffix, start=None, end=None):#是否已xx結尾 """Return True if the string ends with the specified suffix, otherwise return False. :type suffix: string | tuple :type start: numbers.Integral | None :type end: numbers.Integral | None :rtype: bool """ return False def find(self, sub, start=None, end=None):#字符串的查找 """Return the lowest index in the string where substring sub is found, such that sub is contained in the slice s[start:end]. :type sub: string :type start: numbers.Integral | None :type end: numbers.Integral | none :rtype: int """ return 0 def format(self, *args, **kwargs):#格式化字符串 """Perform a string formatting operation. :rtype: string """ return '' def index(self, sub, start=None, end=None):#查找字符串裏子字符第一次出現的位置 """Like find(), but raise ValueError when the substring is not found. :type sub: string :type start: numbers.Integral | None :type end: numbers.Integral | none :rtype: int """ return 0 def isalnum(self):#是否全是字母和數字 """Return true if all characters in the string are alphanumeric and there is at least one character, false otherwise. :rtype: bool """ return False def isalpha(self):#是否全是字母 """Return true if all characters in the string are alphabetic and there is at least one character, false otherwise. :rtype: bool """ return False def isdigit(self):#是否全是數字 """Return true if all characters in the string are digits and there is at least one character, false otherwise. :rtype: bool """ return False def islower(self):#字符串中的字母是否全是小寫 """Return true if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. :rtype: bool """ return False def isspace(self):#是否全是空白字符 """Return true if there are only whitespace characters in the string and there is at least one character, false otherwise. :rtype: bool """ return False def istitle(self):#是否首字母大寫 """Return true if the string is a titlecased string and there is at least one character, for example uppercase characters may only follow uncased characters and lowercase characters only cased ones. :rtype: bool """ return False def isupper(self):#字符串中的字母是都大寫 """Return true if all cased characters in the string are uppercase and there is at least one cased character, false otherwise. :rtype: bool """ return False def join(self, iterable):#字符串的連接 """Return a string which is the concatenation of the strings in the iterable. :type iterable: collections.Iterable[string] :rtype: string """ return '' def ljust(self, width, fillchar=' '):#輸出字符左對齊 """Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space). :type width: numbers.Integral :type fillchar: str :rtype: str """ return b'' def lower(self):#字符中的字母是否全是小寫 """Return a copy of the string with all the cased characters converted to lowercase. :rtype: str """ return b'' def lstrip(self, chars=None):#取出空格及特殊字符 """Return a copy of the string with leading characters removed. :type chars: string | None :rtype: str """ return b'' def partition(self, sep):#字符串拆分 默認拆成三部分 """Split the string at the first occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. :type sep: string :rtype: (str, str, str) """ return b'', b'', b'' def replace(self, old, new, count=-1):#字符串替換 """Return a copy of the string with all occurrences of substring old replaced by new. :type old: string :type new: string :type count: numbers.Integral :rtype: string """ return '' def rfind(self, sub, start=None, end=None):#右側查找 第一次出現 """Return the highest index in the string where substring sub is found, such that sub is contained within s[start:end]. :type sub: string :type start: numbers.Integral | None :type end: numbers.Integral | none :rtype: int """ return 0 def rindex(self, sub, start=None, end=None):##右側查找 第一次出現位置
"""Like rfind(), but raise ValueError when the substring is not found. :type sub: string :type start: numbers.Integral | None :type end: numbers.Integral | none :rtype: int """ return 0 def rjust(self, width, fillchar=' '):#右對齊 """Return the string right justified in a string of length width. Padding is done using the specified fillchar (default is a space). :type width: numbers.Integral :type fillchar: string :rtype: string """ return '' def rpartition(self, sep):#從右側拆分 """Split the string at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. :type sep: string :rtype: (str, str, str) """ return b'', b'', b'' def rsplit(self, sep=None, maxsplit=-1):#字符串的分割 """Return a list of the words in the string, using sep as the delimiter string. :type sep: string | None :type maxsplit: numbers.Integral :rtype: list[str] """ return [] def rstrip(self, chars=None):#去掉字符串的右側空格 """Return a copy of the string with trailing characters removed. :type chars: string | None :rtype: str """ return b'' def split(self, sep=None, maxsplit=-1):#字符串的切割 """Return a list of the words in the string, using sep as the delimiter string. :type sep: string | None :type maxsplit: numbers.Integral :rtype: list[str] """ return [] def splitlines(self, keepends=False):#把字符串按照行切割成list """Return a list of the lines in the string, breaking at line boundaries. :type keepends: bool :rtype: list[str] """ return [] def startswith(self, prefix, start=None, end=None):#以xx開頭 """Return True if string starts with the prefix, otherwise return False. :type prefix: string | tuple :type start: numbers.Integral | None :type end: numbers.Integral | None :rtype: bool """ return False def strip(self, chars=None):#去除左右空格 """Return a copy of the string with the leading and trailing characters removed. :type chars: string | None :rtype: str """ return b'' def swapcase(self):#大小寫互換 """Return a copy of the string with uppercase characters converted to lowercase and vice versa. :rtype: str """ return b'' def title(self):#標題化字符串 """Return a titlecased version of the string where words start with an uppercase character and the remaining characters are lowercase. :rtype: str """ return b'' def upper(self):#大寫 """Return a copy of the string with all the cased characters converted to uppercase. :rtype: str """ return b'' def zfill(self, width):#變成特定長度,不足0補齊 """Return the numeric string left filled with zeros in a string of length width. :type width: numbers.Integral :rtype: str """ return b'' 以上是字符串類中的所有方法包含特殊方法。翻譯不夠準確,請諒解

最後更新:2017-06-25 22:35:23

  上一篇:go  標題
  下一篇:go  scikit-learn學習之神經網絡算法