Day 2 Python之循序渐进2

1.Python编码

   通过Python将文件读到内存,分析内容--转换成字节码,CPU执行机器码

   ex:  Python /home/dev/hello.py

   执行hello.py的过程:

   

   解释器:

#! /usr/bin/env python

./hello.py    #hello.py 由上面这个环境执行

   内容编码:

#! /usr/bin/env python   定义代码执行环境
# -*- coding:utf-8 -*-   将代码转换成utf-8格式表示

# ASCII(8位)-->unicode(万国码)至少16位,2的16次方 --> utf-8 (对万国码的压缩和优化,对数字,字母,字符按照8位存)

# utf-8 欧洲字母用两个字节存(16),汉字用三个字节存(24)
# python2.7 默认用unicode 表示,需要编码转换,见下图:

python3.x默认编码为utf-8

代码注释:

单行注释: #
多行注释: '''code''' 或者“”“ ”“”

2.接受执行参数

   python p.py  runserver 0.0.0.0(传入参数)

   

1 #! /usr/bin/env python
2 # -*- coding:utf-8 -*-
3 
4 import sys   # 默认解释器代码放在sys中提供调用
5 print(sys.argv)
View Code

 sys.argv 用来接收python解释器所有的参数封装到argv里面,argv类型为列表

 

pyc文件:

  pyc字节码文件通过.py文件生成,修改和删除后再次执行*.py依然会生成或者覆盖。

3.Python字符串原理

   3.1 内存中维护一个小数字池(作为缓存用,缓冲池),范围:-5 ~ 257

   3.2 字符串(内部算法),列表,元组都一样

 

4.基本数据类型常用方法

  4.1 基本的5中数据类型

  •  Int 整型(表示和数字方法一样)

          如11,22,33,55,66      

          在32位机器上,整数的位数为32,取值范围:-2**31~2**31-1

          在64位机器上,整数的位数为64,取值范围 :-2**63~2**63-1

Class Int
  • long长整型

          与C不同,python长整数没有指定位宽,从2.2版本起,如果整数发生溢出,python会自动将整数转换为长整数类型,即+L

          可能如:15656543649、48489464246544564654 

class long(object):
    """
    long(x=0) -> long
    long(x, base=10) -> long
    
    Convert a number or string to a long integer, or return 0L if no arguments
    are given.  If x is floating point, the conversion truncates towards zero.
    
    If x is not a number or if base is given, then x must be a string or
    Unicode object representing an integer literal in the given base.  The
    literal can be preceded by '+' or '-' and be surrounded by whitespace.
    The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
    interpret the base from the string as an integer literal.
    >>> int('0b100', base=0)
    4L
    """
    def bit_length(self): # real signature unknown; restored from __doc__
        """
        long.bit_length() -> int or long
        
        Number of bits necessary to represent self in binary.
        >>> bin(37L)
        '0b100101'
        >>> (37L).bit_length()
        """
        return 0

    def conjugate(self, *args, **kwargs): # real signature unknown
        """ Returns self, the complex conjugate of any long. """
        pass

    def __abs__(self): # real signature unknown; restored from __doc__
        """ x.__abs__() <==> abs(x) """
        pass

    def __add__(self, y): # real signature unknown; restored from __doc__
        """ x.__add__(y) <==> x+y """
        pass

    def __and__(self, y): # real signature unknown; restored from __doc__
        """ x.__and__(y) <==> x&y """
        pass

    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ x.__cmp__(y) <==> cmp(x,y) """
        pass

    def __coerce__(self, y): # real signature unknown; restored from __doc__
        """ x.__coerce__(y) <==> coerce(x, y) """
        pass

    def __divmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__divmod__(y) <==> divmod(x, y) """
        pass

    def __div__(self, y): # real signature unknown; restored from __doc__
        """ x.__div__(y) <==> x/y """
        pass

    def __float__(self): # real signature unknown; restored from __doc__
        """ x.__float__() <==> float(x) """
        pass

    def __floordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__floordiv__(y) <==> x//y """
        pass

    def __format__(self, *args, **kwargs): # real signature unknown
        pass

    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass

    def __hash__(self): # real signature unknown; restored from __doc__
        """ x.__hash__() <==> hash(x) """
        pass

    def __hex__(self): # real signature unknown; restored from __doc__
        """ x.__hex__() <==> hex(x) """
        pass

    def __index__(self): # real signature unknown; restored from __doc__
        """ x[y:z] <==> x[y.__index__():z.__index__()] """
        pass

    def __init__(self, x=0): # real signature unknown; restored from __doc__
        pass

    def __int__(self): # real signature unknown; restored from __doc__
        """ x.__int__() <==> int(x) """
        pass

    def __invert__(self): # real signature unknown; restored from __doc__
        """ x.__invert__() <==> ~x """
        pass

    def __long__(self): # real signature unknown; restored from __doc__
        """ x.__long__() <==> long(x) """
        pass

    def __lshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__lshift__(y) <==> x<<y """
        pass

    def __mod__(self, y): # real signature unknown; restored from __doc__
        """ x.__mod__(y) <==> x%y """
        pass

    def __mul__(self, y): # real signature unknown; restored from __doc__
        """ x.__mul__(y) <==> x*y """
        pass

    def __neg__(self): # real signature unknown; restored from __doc__
        """ x.__neg__() <==> -x """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __nonzero__(self): # real signature unknown; restored from __doc__
        """ x.__nonzero__() <==> x != 0 """
        pass

    def __oct__(self): # real signature unknown; restored from __doc__
        """ x.__oct__() <==> oct(x) """
        pass

    def __or__(self, y): # real signature unknown; restored from __doc__
        """ x.__or__(y) <==> x|y """
        pass

    def __pos__(self): # real signature unknown; restored from __doc__
        """ x.__pos__() <==> +x """
        pass

    def __pow__(self, y, z=None): # real signature unknown; restored from __doc__
        """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
        pass

    def __radd__(self, y): # real signature unknown; restored from __doc__
        """ x.__radd__(y) <==> y+x """
        pass

    def __rand__(self, y): # real signature unknown; restored from __doc__
        """ x.__rand__(y) <==> y&x """
        pass

    def __rdivmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__rdivmod__(y) <==> divmod(y, x) """
        pass

    def __rdiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rdiv__(y) <==> y/x """
        pass

    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass

    def __rfloordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rfloordiv__(y) <==> y//x """
        pass

    def __rlshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rlshift__(y) <==> y<<x """
        pass

    def __rmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__rmod__(y) <==> y%x """
        pass

    def __rmul__(self, y): # real signature unknown; restored from __doc__
        """ x.__rmul__(y) <==> y*x """
        pass

    def __ror__(self, y): # real signature unknown; restored from __doc__
        """ x.__ror__(y) <==> y|x """
        pass

    def __rpow__(self, x, z=None): # real signature unknown; restored from __doc__
        """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
        pass

    def __rrshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rrshift__(y) <==> y>>x """
        pass

    def __rshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rshift__(y) <==> x>>y """
        pass

    def __rsub__(self, y): # real signature unknown; restored from __doc__
        """ x.__rsub__(y) <==> y-x """
        pass

    def __rtruediv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rtruediv__(y) <==> y/x """
        pass

    def __rxor__(self, y): # real signature unknown; restored from __doc__
        """ x.__rxor__(y) <==> y^x """
        pass

    def __sizeof__(self, *args, **kwargs): # real signature unknown
        """ Returns size in memory, in bytes """
        pass

    def __str__(self): # real signature unknown; restored from __doc__
        """ x.__str__() <==> str(x) """
        pass

    def __sub__(self, y): # real signature unknown; restored from __doc__
        """ x.__sub__(y) <==> x-y """
        pass

    def __truediv__(self, y): # real signature unknown; restored from __doc__
        """ x.__truediv__(y) <==> x/y """
        pass

    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ Truncating an Integral returns itself. """
        pass

    def __xor__(self, y): # real signature unknown; restored from __doc__
        """ x.__xor__(y) <==> x^y """
        pass

    denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the denominator of a rational number in lowest terms"""

    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the imaginary part of a complex number"""

    numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the numerator of a rational number in lowest terms"""

    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the real part of a complex number"""

long
long
  • Float浮点型

        如:3.14159,6.5539  (通常说为带小数点的)

class float(object):
    """
    float(x) -> floating point number
    
    Convert a string or number to a floating point number, if possible.
    """
    def as_integer_ratio(self):   
        """ 获取改值的最简比 """
        """
        float.as_integer_ratio() -> (int, int)

        Return a pair of integers, whose ratio is exactly equal to the original
        float and with a positive denominator.
        Raise OverflowError on infinities and a ValueError on NaNs.

        >>> (10.0).as_integer_ratio()
        (10, 1)
        >>> (0.0).as_integer_ratio()
        (0, 1)
        >>> (-.25).as_integer_ratio()
        (-1, 4)
        """
        pass

    def conjugate(self, *args, **kwargs): # real signature unknown
        """ Return self, the complex conjugate of any float. """
        pass

    def fromhex(self, string):   
        """ 将十六进制字符串转换成浮点型 """
        """
        float.fromhex(string) -> float
        
        Create a floating-point number from a hexadecimal string.
        >>> float.fromhex('0x1.ffffp10')
        2047.984375
        >>> float.fromhex('-0x1p-1074')
        -4.9406564584124654e-324
        """
        return 0.0

    def hex(self):   
        """ 返回当前值的 16 进制表示 """
        """
        float.hex() -> string
        
        Return a hexadecimal representation of a floating-point number.
        >>> (-0.1).hex()
        '-0x1.999999999999ap-4'
        >>> 3.14159.hex()
        '0x1.921f9f01b866ep+1'
        """
        return ""

    def is_integer(self, *args, **kwargs): # real signature unknown
        """ Return True if the float is an integer. """
        pass

    def __abs__(self):   
        """ x.__abs__() <==> abs(x) """
        pass

    def __add__(self, y):   
        """ x.__add__(y) <==> x+y """
        pass

    def __coerce__(self, y):   
        """ x.__coerce__(y) <==> coerce(x, y) """
        pass

    def __divmod__(self, y):   
        """ x.__divmod__(y) <==> divmod(x, y) """
        pass

    def __div__(self, y):   
        """ x.__div__(y) <==> x/y """
        pass

    def __eq__(self, y):   
        """ x.__eq__(y) <==> x==y """
        pass

    def __float__(self):   
        """ x.__float__() <==> float(x) """
        pass

    def __floordiv__(self, y):   
        """ x.__floordiv__(y) <==> x//y """
        pass

    def __format__(self, format_spec):   
        """
        float.__format__(format_spec) -> string
        
        Formats the float according to format_spec.
        """
        return ""

    def __getattribute__(self, name):   
        """ x.__getattribute__('name') <==> x.name """
        pass

    def __getformat__(self, typestr):   
        """
        float.__getformat__(typestr) -> string
        
        You probably don't want to use this function.  It exists mainly to be
        used in Python's test suite.
        
        typestr must be 'double' or 'float'.  This function returns whichever of
        'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the
        format of floating point numbers used by the C type named by typestr.
        """
        return ""

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass

    def __ge__(self, y):   
        """ x.__ge__(y) <==> x>=y """
        pass

    def __gt__(self, y):   
        """ x.__gt__(y) <==> x>y """
        pass

    def __hash__(self):   
        """ x.__hash__() <==> hash(x) """
        pass

    def __init__(self, x):   
        pass

    def __int__(self):   
        """ x.__int__() <==> int(x) """
        pass

    def __le__(self, y):   
        """ x.__le__(y) <==> x<=y """
        pass

    def __long__(self):   
        """ x.__long__() <==> long(x) """
        pass

    def __lt__(self, y):   
        """ x.__lt__(y) <==> x<y """
        pass

    def __mod__(self, y):   
        """ x.__mod__(y) <==> x%y """
        pass

    def __mul__(self, y):   
        """ x.__mul__(y) <==> x*y """
        pass

    def __neg__(self):   
        """ x.__neg__() <==> -x """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more):   
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __ne__(self, y):   
        """ x.__ne__(y) <==> x!=y """
        pass

    def __nonzero__(self):   
        """ x.__nonzero__() <==> x != 0 """
        pass

    def __pos__(self):   
        """ x.__pos__() <==> +x """
        pass

    def __pow__(self, y, z=None):   
        """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
        pass

    def __radd__(self, y):   
        """ x.__radd__(y) <==> y+x """
        pass

    def __rdivmod__(self, y):   
        """ x.__rdivmod__(y) <==> divmod(y, x) """
        pass

    def __rdiv__(self, y):   
        """ x.__rdiv__(y) <==> y/x """
        pass

    def __repr__(self):   
        """ x.__repr__() <==> repr(x) """
        pass

    def __rfloordiv__(self, y):   
        """ x.__rfloordiv__(y) <==> y//x """
        pass

    def __rmod__(self, y):   
        """ x.__rmod__(y) <==> y%x """
        pass

    def __rmul__(self, y):   
        """ x.__rmul__(y) <==> y*x """
        pass

    def __rpow__(self, x, z=None):   
        """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
        pass

    def __rsub__(self, y):   
        """ x.__rsub__(y) <==> y-x """
        pass

    def __rtruediv__(self, y):   
        """ x.__rtruediv__(y) <==> y/x """
        pass

    def __setformat__(self, typestr, fmt):   
        """
        float.__setformat__(typestr, fmt) -> None
        
        You probably don't want to use this function.  It exists mainly to be
        used in Python's test suite.
        
        typestr must be 'double' or 'float'.  fmt must be one of 'unknown',
        'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be
        one of the latter two if it appears to match the underlying C reality.
        
        Override the automatic determination of C-level floating point type.
        This affects how floats are converted to and from binary strings.
        """
        pass

    def __str__(self):   
        """ x.__str__() <==> str(x) """
        pass

    def __sub__(self, y):   
        """ x.__sub__(y) <==> x-y """
        pass

    def __truediv__(self, y):   
        """ x.__truediv__(y) <==> x/y """
        pass

    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ Return the Integral closest to x between 0 and x. """
        pass

    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the imaginary part of a complex number"""

    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the real part of a complex number"""

float
Float
  • bool布尔型

        即是Ture 和 False;  0或1

        可以使用and / or /not

  • None空值

        不能理解为0,一个特殊的空值

  • complex复数

        由实数和虚数组成,一般表现为X+Y

 

字符串:

如:“leon”,"jack" ==

万恶的字符串拼接

ex:

s = "leon"

其实是字符数组['l','e','o','n']

如果['l','e','o','n']+y   内存会自动开辟空间['l','e','o','n','y']

用字符串格式化只会增加两次

考虑程序的垃圾回收机制问题

print "i am %s %s %s %s " % name

         i am %s %s %s %s 

字符串常用功能:

  • 移除空白 (strip)
  • 分割        (split)
  • 长度        (len)
  • 索引        obj[1]
  • 切片        obj[1:],obj[1:10]

字符串具备功能:

class str(basestring):
    """
    str(object='') -> string
    
    Return a nice string representation of the object.
    If the argument is a string, the return value is the same object.
    """
    def capitalize(self):  
        """ 首字母变大写 """
        """
        S.capitalize() -> string
        
        Return a copy of the string S with only its first character
        capitalized.
        """
        return ""

    def center(self, width, fillchar=None):  
        """ 内容居中,width:总长度;fillchar:空白处填充内容,默认无 """
        """
        S.center(width[, fillchar]) -> string
        
        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):  
        """ 子序列个数 """
        """
        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.
        """
        return 0

    def decode(self, encoding=None, errors=None):  
        """ 解码 """
        """
        S.decode([encoding[,errors]]) -> object
        
        Decodes S using the codec registered for encoding. encoding defaults
        to the default encoding. errors may be given to set a different error
        handling scheme. Default is 'strict' meaning that encoding errors raise
        a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
        as well as any other name registered with codecs.register_error that is
        able to handle UnicodeDecodeErrors.
        """
        return object()

    def encode(self, encoding=None, errors=None):  
        """ 编码,针对unicode """
        """
        S.encode([encoding[,errors]]) -> object
        
        Encodes S using the codec registered for encoding. encoding defaults
        to the default encoding. 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 is able to handle UnicodeEncodeErrors.
        """
        return object()

    def endswith(self, suffix, start=None, end=None):  
        """ 是否以 xxx 结束 """
        """
        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.
        """
        return False

    def expandtabs(self, tabsize=None):  
        """ 将tab转换成空格,默认一个tab转换成8个空格 """
        """
        S.expandtabs([tabsize]) -> string
        
        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):  
        """ 寻找子序列位置,如果没找到,返回 -1 """
        """
        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.
        """
        return 0

    def format(*args, **kwargs): # known special case of str.format
        """ 字符串格式化,动态参数,将函数式编程时细说 """
        """
        S.format(*args, **kwargs) -> string
        
        Return a formatted version of S, using substitutions from args and kwargs.
        The substitutions are identified by braces ('{' and '}').
        """
        pass

    def index(self, sub, start=None, end=None):  
        """ 子序列位置,如果没找到,报错 """
        S.index(sub [,start [,end]]) -> int
        
        Like S.find() but raise ValueError when the substring is not found.
        """
        return 0

    def isalnum(self):  
        """ 是否是字母和数字 """
        """
        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):  
        """ 是否是字母 """
        """
        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 isdigit(self):  
        """ 是否是数字 """
        """
        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):  
        """ 是否小写 """
        """
        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.
        """
        return False

    def isspace(self):  
        """
        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):  
        """
        S.istitle() -> bool
        
        Return True if S is a titlecased string and there is at least one
        character in S, i.e. uppercase characters may only follow uncased
        characters and lowercase characters only cased ones. Return False
        otherwise.
        """
        return False

    def isupper(self):  
        """
        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.
        """
        return False

    def join(self, iterable):  
        """ 连接 """
        """
        S.join(iterable) -> string
        
        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):  
        """ 内容左对齐,右侧填充 """
        """
        S.ljust(width[, fillchar]) -> string
        
        Return S left-justified in a string of length width. Padding is
        done using the specified fill character (default is a space).
        """
        return ""

    def lower(self):  
        """ 变小写 """
        """
        S.lower() -> string
        
        Return a copy of the string S converted to lowercase.
        """
        return ""

    def lstrip(self, chars=None):  
        """ 移除左侧空白 """
        """
        S.lstrip([chars]) -> string or unicode
        
        Return a copy of the string S with leading whitespace removed.
        If chars is given and not None, remove characters in chars instead.
        If chars is unicode, S will be converted to unicode before stripping
        """
        return ""

    def partition(self, sep):  
        """ 分割,前,中,后三部分 """
        """
        S.partition(sep) -> (head, sep, tail)
        
        Search for the separator sep in S, and return the part before it,
        the separator itself, and the part after it.  If the separator is not
        found, return S and two empty strings.
        """
        pass

    def replace(self, old, new, count=None):  
        """ 替换 """
        """
        S.replace(old, new[, count]) -> string
        
        Return a copy of string S with all occurrences of substring
        old replaced by new.  If the optional argument count is
        given, only the first count occurrences are replaced.
        """
        return ""

    def rfind(self, sub, start=None, end=None):  
        """
        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.
        
        Return -1 on failure.
        """
        return 0

    def rindex(self, sub, start=None, end=None):  
        """
        S.rindex(sub [,start [,end]]) -> int
        
        Like S.rfind() but raise ValueError when the substring is not found.
        """
        return 0

    def rjust(self, width, fillchar=None):  
        """
        S.rjust(width[, fillchar]) -> string
        
        Return S right-justified in a string of length width. Padding is
        done using the specified fill character (default is a space)
        """
        return ""

    def rpartition(self, sep):  
        """
        S.rpartition(sep) -> (head, sep, tail)
        
        Search for the separator sep in S, starting at the end of S, and return
        the part before it, the separator itself, and the part after it.  If the
        separator is not found, return two empty strings and S.
        """
        pass

    def rsplit(self, sep=None, maxsplit=None):  
        """
        S.rsplit([sep [,maxsplit]]) -> list of strings
        
        Return a list of the words in the string 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 or is None, any whitespace string
        is a separator.
        """
        return []

    def rstrip(self, chars=None):  
        """
        S.rstrip([chars]) -> string or unicode
        
        Return a copy of the string S with trailing whitespace removed.
        If chars is given and not None, remove characters in chars instead.
        If chars is unicode, S will be converted to unicode before stripping
        """
        return ""

    def split(self, sep=None, maxsplit=None):  
        """ 分割, maxsplit最多分割几次 """
        """
        S.split([sep [,maxsplit]]) -> list of strings
        
        Return a list of the words in the string 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.
        """
        return []

    def splitlines(self, keepends=False):  
        """ 根据换行分割 """
        """
        S.splitlines(keepends=False) -> list of strings
        
        Return a list of the lines in S, breaking at line boundaries.
        Line breaks are not included in the resulting list unless keepends
        is given and true.
        """
        return []

    def startswith(self, prefix, start=None, end=None):  
        """ 是否起始 """
        """
        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.
        """
        return False

    def strip(self, chars=None):  
        """ 移除两段空白 """
        """
        S.strip([chars]) -> string or unicode
        
        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.
        If chars is unicode, S will be converted to unicode before stripping
        """
        return ""

    def swapcase(self):  
        """ 大写变小写,小写变大写 """
        """
        S.swapcase() -> string
        
        Return a copy of the string S with uppercase characters
        converted to lowercase and vice versa.
        """
        return ""

    def title(self):  
        """
        S.title() -> string
        
        Return a titlecased version of S, i.e. words start with uppercase
        characters, all remaining cased characters have lowercase.
        """
        return ""

    def translate(self, table, deletechars=None):  
        """
        转换,需要先做一个对应表,最后一个表示删除字符集合
        intab = "aeiou"
        outtab = "12345"
        trantab = maketrans(intab, outtab)
        str = "this is string example....wow!!!"
        print str.translate(trantab, 'xm')
        """

        """
        S.translate(table [,deletechars]) -> string
        
        Return a copy of the string S, where all characters occurring
        in the optional argument deletechars are removed, and the
        remaining characters have been mapped through the given
        translation table, which must be a string of length 256 or None.
        If the table argument is None, no translation is applied and
        the operation simply removes the characters in deletechars.
        """
        return ""

    def upper(self):  
        """
        S.upper() -> string
        
        Return a copy of the string S converted to uppercase.
        """
        return ""

    def zfill(self, width):  
        """方法返回指定长度的字符串,原字符串右对齐,前面填充0。"""
        """
        S.zfill(width) -> string
        
        Pad a numeric string S with zeros on the left, to fill a field
        of the specified width.  The string S is never truncated.
        """
        return ""

    def _formatter_field_name_split(self, *args, **kwargs): # real signature unknown
        pass

    def _formatter_parser(self, *args, **kwargs): # real signature unknown
        pass

    def __add__(self, y):  
        """ x.__add__(y) <==> x+y """
        pass

    def __contains__(self, y):  
        """ x.__contains__(y) <==> y in x """
        pass

    def __eq__(self, y):  
        """ x.__eq__(y) <==> x==y """
        pass

    def __format__(self, format_spec):  
        """
        S.__format__(format_spec) -> string
        
        Return a formatted version of S as described by format_spec.
        """
        return ""

    def __getattribute__(self, name):  
        """ x.__getattribute__('name') <==> x.name """
        pass

    def __getitem__(self, y):  
        """ x.__getitem__(y) <==> x[y] """
        pass

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass

    def __getslice__(self, i, j):  
        """
        x.__getslice__(i, j) <==> x[i:j]
                   
                   Use of negative indices is not supported.
        """
        pass

    def __ge__(self, y):  
        """ x.__ge__(y) <==> x>=y """
        pass

    def __gt__(self, y):  
        """ x.__gt__(y) <==> x>y """
        pass

    def __hash__(self):  
        """ x.__hash__() <==> hash(x) """
        pass

    def __init__(self, string=''): # known special case of str.__init__
        """
        str(object='') -> string
        
        Return a nice string representation of the object.
        If the argument is a string, the return value is the same object.
        # (copied from class doc)
        """
        pass

    def __len__(self):  
        """ x.__len__() <==> len(x) """
        pass

    def __le__(self, y):  
        """ x.__le__(y) <==> x<=y """
        pass

    def __lt__(self, y):  
        """ x.__lt__(y) <==> x<y """
        pass

    def __mod__(self, y):  
        """ x.__mod__(y) <==> x%y """
        pass

    def __mul__(self, n):  
        """ x.__mul__(n) <==> x*n """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more):  
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __ne__(self, y):  
        """ x.__ne__(y) <==> x!=y """
        pass

    def __repr__(self):  
        """ x.__repr__() <==> repr(x) """
        pass

    def __rmod__(self, y):  
        """ x.__rmod__(y) <==> y%x """
        pass

    def __rmul__(self, n):  
        """ x.__rmul__(n) <==> n*x """
        pass

    def __sizeof__(self):  
        """ S.__sizeof__() -> size of S in memory, in bytes """
        pass

    def __str__(self):  
        """ x.__str__() <==> str(x) """
        pass

str
str

列表:

如:[11,22,33]、['leon', 'jack']

l1 = [1,2,3,4,5,6] 或 l1 = list(1,2,3,4,5,6)

常用方法:

索引: index

切片: :

追加:append

删除:del   remove pop

长度:len

循环:for,while, (foreach)

        循环中断:break;continue;pass(占位);return;exit(退出整个程序)

包含:in , _contains_  

ex: 'leon'  in ['beijing'],

每个列表都具备如下功能:

class list(object):
    """
    list() -> new empty list
    list(iterable) -> new list initialized from iterable's items
    """
    def append(self, p_object): # real signature unknown; restored from __doc__
        """ L.append(object) -- append object to end """
        pass

    def count(self, value): # real signature unknown; restored from __doc__
        """ L.count(value) -> integer -- return number of occurrences of value """
        return 0

    def extend(self, iterable): # real signature unknown; restored from __doc__
        """ L.extend(iterable) -- extend list by appending elements from the iterable """
        pass

    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
        """
        L.index(value, [start, [stop]]) -> integer -- return first index of value.
        Raises ValueError if the value is not present.
        """
        return 0

    def insert(self, index, p_object): # real signature unknown; restored from __doc__
        """ L.insert(index, object) -- insert object before index """
        pass

    def pop(self, index=None): # real signature unknown; restored from __doc__
        """
        L.pop([index]) -> item -- remove and return item at index (default last).
        Raises IndexError if list is empty or index is out of range.
        """
        pass

    def remove(self, value): # real signature unknown; restored from __doc__
        """
        L.remove(value) -- remove first occurrence of value.
        Raises ValueError if the value is not present.
        """
        pass

    def reverse(self): # real signature unknown; restored from __doc__
        """ L.reverse() -- reverse *IN PLACE* """
        pass

    def sort(self, cmp=None, key=None, reverse=False): # real signature unknown; restored from __doc__
        """
        L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
        cmp(x, y) -> -1, 0, 1
        """
        pass

    def __add__(self, y): # real signature unknown; restored from __doc__
        """ x.__add__(y) <==> x+y """
        pass

    def __contains__(self, y): # real signature unknown; restored from __doc__
        """ x.__contains__(y) <==> y in x """
        pass

    def __delitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__delitem__(y) <==> del x[y] """
        pass

    def __delslice__(self, i, j): # real signature unknown; restored from __doc__
        """
        x.__delslice__(i, j) <==> del x[i:j]
                   
                   Use of negative indices is not supported.
        """
        pass

    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ x.__eq__(y) <==> x==y """
        pass

    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass

    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__getitem__(y) <==> x[y] """
        pass

    def __getslice__(self, i, j): # real signature unknown; restored from __doc__
        """
        x.__getslice__(i, j) <==> x[i:j]
                   
                   Use of negative indices is not supported.
        """
        pass

    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ x.__ge__(y) <==> x>=y """
        pass

    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ x.__gt__(y) <==> x>y """
        pass

    def __iadd__(self, y): # real signature unknown; restored from __doc__
        """ x.__iadd__(y) <==> x+=y """
        pass

    def __imul__(self, y): # real signature unknown; restored from __doc__
        """ x.__imul__(y) <==> x*=y """
        pass

    def __init__(self, seq=()): # known special case of list.__init__
        """
        list() -> new empty list
        list(iterable) -> new list initialized from iterable's items
        # (copied from class doc)
        """
        pass

    def __iter__(self): # real signature unknown; restored from __doc__
        """ x.__iter__() <==> iter(x) """
        pass

    def __len__(self): # real signature unknown; restored from __doc__
        """ x.__len__() <==> len(x) """
        pass

    def __le__(self, y): # real signature unknown; restored from __doc__
        """ x.__le__(y) <==> x<=y """
        pass

    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ x.__lt__(y) <==> x<y """
        pass

    def __mul__(self, n): # real signature unknown; restored from __doc__
        """ x.__mul__(n) <==> x*n """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ x.__ne__(y) <==> x!=y """
        pass

    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass

    def __reversed__(self): # real signature unknown; restored from __doc__
        """ L.__reversed__() -- return a reverse iterator over the list """
        pass

    def __rmul__(self, n): # real signature unknown; restored from __doc__
        """ x.__rmul__(n) <==> n*x """
        pass

    def __setitem__(self, i, y): # real signature unknown; restored from __doc__
        """ x.__setitem__(i, y) <==> x[i]=y """
        pass

    def __setslice__(self, i, j, y): # real signature unknown; restored from __doc__
        """
        x.__setslice__(i, j, y) <==> x[i:j]=y
                   
                   Use  of negative indices is not supported.
        """
        pass

    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ L.__sizeof__() -- size of L in memory, in bytes """
        pass

    __hash__ = None

list
list

元组(tuple)

重点:元组的元素不可以修改

(11,22,33,44,55)

(11,22,33,44,55,{'k1':'v1'})元组的元素不能修改,所以里面字典不能修改,但是元素的元素,也就是字典里的值是可以改的

ex:

t1 = (1,2,{'k1':'v1'})

#1,2,{'k1':'v1'}

#del t1[0]

t1[2]['k1'] = 2

print(t1)

#索引、切片、循环、长度、包含  等功能和列表一样

 

字典(dict):

键值对 dic = {'key':‘value’}

常用功能

索引:通过key来找  index

新增:d[key] xx

删除:del d[key]

键、值、键值对: keys \ values \ items

for i in dict(类)

循环:for ==

长度:len

class dict(object):
    """
    dict() -> new empty dictionary
    dict(mapping) -> new dictionary initialized from a mapping object's
        (key, value) pairs
    dict(iterable) -> new dictionary initialized as if via:
        d = {}
        for k, v in iterable:
            d[k] = v
    dict(**kwargs) -> new dictionary initialized with the name=value pairs
        in the keyword argument list.  For example:  dict(one=1, two=2)
    """

    def clear(self): # real signature unknown; restored from __doc__
        """ 清除内容 """
        """ D.clear() -> None.  Remove all items from D. """
        pass

    def copy(self): # real signature unknown; restored from __doc__
        """ 浅拷贝 """
        """ D.copy() -> a shallow copy of D """
        pass

    @staticmethod # known case
    def fromkeys(S, v=None): # real signature unknown; restored from __doc__
        """
        dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
        v defaults to None.
        """
        pass

    def get(self, k, d=None): # real signature unknown; restored from __doc__
        """ 根据key获取值,d是默认值 """
        """ D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None. """
        pass

    def has_key(self, k): # real signature unknown; restored from __doc__
        """ 是否有key """
        """ D.has_key(k) -> True if D has a key k, else False """
        return False

    def items(self): # real signature unknown; restored from __doc__
        """ 所有项的列表形式 """
        """ D.items() -> list of D's (key, value) pairs, as 2-tuples """
        return []

    def iteritems(self): # real signature unknown; restored from __doc__
        """ 项可迭代 """
        """ D.iteritems() -> an iterator over the (key, value) items of D """
        pass

    def iterkeys(self): # real signature unknown; restored from __doc__
        """ key可迭代 """
        """ D.iterkeys() -> an iterator over the keys of D """
        pass

    def itervalues(self): # real signature unknown; restored from __doc__
        """ value可迭代 """
        """ D.itervalues() -> an iterator over the values of D """
        pass

    def keys(self): # real signature unknown; restored from __doc__
        """ 所有的key列表 """
        """ D.keys() -> list of D's keys """
        return []

    def pop(self, k, d=None): # real signature unknown; restored from __doc__
        """ 获取并在字典中移除 """
        """
        D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
        If key is not found, d is returned if given, otherwise KeyError is raised
        """
        pass

    def popitem(self): # real signature unknown; restored from __doc__
        """ 获取并在字典中移除 """
        """
        D.popitem() -> (k, v), remove and return some (key, value) pair as a
        2-tuple; but raise KeyError if D is empty.
        """
        pass

    def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
        """ 如果key不存在,则创建,如果存在,则返回已存在的值且不修改 """
        """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """
        pass

    def update(self, E=None, **F): # known special case of dict.update
        """ 更新
            {'name':'alex', 'age': 18000}
            [('name','sbsbsb'),]
        """
        """
        D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
        If E present and has a .keys() method, does:     for k in E: D[k] = E[k]
        If E present and lacks .keys() method, does:     for (k, v) in E: D[k] = v
        In either case, this is followed by: for k in F: D[k] = F[k]
        """
        pass

    def values(self): # real signature unknown; restored from __doc__
        """ 所有的值 """
        """ D.values() -> list of D's values """
        return []

    def viewitems(self): # real signature unknown; restored from __doc__
        """ 所有项,只是将内容保存至view对象中 """
        """ D.viewitems() -> a set-like object providing a view on D's items """
        pass

    def viewkeys(self): # real signature unknown; restored from __doc__
        """ D.viewkeys() -> a set-like object providing a view on D's keys """
        pass

    def viewvalues(self): # real signature unknown; restored from __doc__
        """ D.viewvalues() -> an object providing a view on D's values """
        pass

    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ x.__cmp__(y) <==> cmp(x,y) """
        pass

    def __contains__(self, k): # real signature unknown; restored from __doc__
        """ D.__contains__(k) -> True if D has a key k, else False """
        return False

    def __delitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__delitem__(y) <==> del x[y] """
        pass

    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ x.__eq__(y) <==> x==y """
        pass

    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass

    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__getitem__(y) <==> x[y] """
        pass

    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ x.__ge__(y) <==> x>=y """
        pass

    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ x.__gt__(y) <==> x>y """
        pass

    def __init__(self, seq=None, **kwargs): # known special case of dict.__init__
        """
        dict() -> new empty dictionary
        dict(mapping) -> new dictionary initialized from a mapping object's
            (key, value) pairs
        dict(iterable) -> new dictionary initialized as if via:
            d = {}
            for k, v in iterable:
                d[k] = v
        dict(**kwargs) -> new dictionary initialized with the name=value pairs
            in the keyword argument list.  For example:  dict(one=1, two=2)
        # (copied from class doc)
        """
        pass

    def __iter__(self): # real signature unknown; restored from __doc__
        """ x.__iter__() <==> iter(x) """
        pass

    def __len__(self): # real signature unknown; restored from __doc__
        """ x.__len__() <==> len(x) """
        pass

    def __le__(self, y): # real signature unknown; restored from __doc__
        """ x.__le__(y) <==> x<=y """
        pass

    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ x.__lt__(y) <==> x<y """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ x.__ne__(y) <==> x!=y """
        pass

    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass

    def __setitem__(self, i, y): # real signature unknown; restored from __doc__
        """ x.__setitem__(i, y) <==> x[i]=y """
        pass

    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ D.__sizeof__() -> size of D in memory, in bytes """
        pass

    __hash__ = None

dict
dict

5.Python主文件判断

   if _name_=='_main_':

       main()   #主入口文件

ex:

1.py     _name_   1

index.py    _name_=='_main_'

python index

 

6.一切事物皆为对象

name = 'jack'    对象

li = [11,22,33]   对象

对象调用类里面的方法实现功能

 

7.int内部功能介绍

查看对象由那个类创建

age =  18
print (type(age))
输出:

   C:\Python35\python35.exe "D:/Python/python代码/Day 04/test.py"
   <class 'int'>

 用type可以找到类的位置:

或者直接abs(-19),  abs内部会先创建数字对象,执行对象的abs方法。

方法:

  1 class int(object):
  2     """
  3     int(x=0) -> int or long
  4     int(x, base=10) -> int or long
  5     
  6     Convert a number or string to an integer, or return 0 if no arguments
  7     are given.  If x is floating point, the conversion truncates towards zero.
  8     If x is outside the integer range, the function returns a long instead.
  9     
 10     If x is not a number or if base is given, then x must be a string or
 11     Unicode object representing an integer literal in the given base.  The
 12     literal can be preceded by '+' or '-' and be surrounded by whitespace.
 13     The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
 14     interpret the base from the string as an integer literal.
 15     >>> int('0b100', base=0)
 16     """
 17     def bit_length(self): 
 18         """ 返回表示该数字的时占用的最少位数 """
 19         """
 20         int.bit_length() -> int
 21         
 22         Number of bits necessary to represent self in binary.
 23         >>> bin(37)
 24         '0b100101'
 25         >>> (37).bit_length()
 26         """
 27         return 0
 28 
 29     def conjugate(self, *args, **kwargs): # real signature unknown
 30         """ 返回该复数的共轭复数 """
 31         """ Returns self, the complex conjugate of any int. """
 32         pass
 33 
 34     def __abs__(self):
 35         """ 返回绝对值 """
 36         """ x.__abs__() <==> abs(x) """
 37         pass
 38 
 39     def __add__(self, y):
 40         """ x.__add__(y) <==> x+y """
 41         pass
 42 
 43     def __and__(self, y):
 44         """ x.__and__(y) <==> x&y """
 45         pass
 46 
 47     def __cmp__(self, y): 
 48         """ 比较两个数大小 """
 49         """ x.__cmp__(y) <==> cmp(x,y) """
 50         pass
 51 
 52     def __coerce__(self, y):
 53         """ 强制生成一个元组 """ 
 54         """ x.__coerce__(y) <==> coerce(x, y) """
 55         pass
 56 
 57     def __divmod__(self, y): 
 58         """ 相除,得到商和余数组成的元组 """ 
 59         """ x.__divmod__(y) <==> divmod(x, y) """
 60         pass
 61 
 62     def __div__(self, y): 
 63         """ x.__div__(y) <==> x/y """
 64         pass
 65 
 66     def __float__(self): 
 67         """ 转换为浮点类型 """ 
 68         """ x.__float__() <==> float(x) """
 69         pass
 70 
 71     def __floordiv__(self, y): 
 72         """ x.__floordiv__(y) <==> x//y """
 73         pass
 74 
 75     def __format__(self, *args, **kwargs): # real signature unknown
 76         pass
 77 
 78     def __getattribute__(self, name): 
 79         """ x.__getattribute__('name') <==> x.name """
 80         pass
 81 
 82     def __getnewargs__(self, *args, **kwargs): # real signature unknown
 83         """ 内部调用 __new__方法或创建对象时传入参数使用 """ 
 84         pass
 85 
 86     def __hash__(self): 
 87         """如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等。"""
 88         """ x.__hash__() <==> hash(x) """
 89         pass
 90 
 91     def __hex__(self): 
 92         """ 返回当前数的 十六进制 表示 """ 
 93         """ x.__hex__() <==> hex(x) """
 94         pass
 95 
 96     def __index__(self): 
 97         """ 用于切片,数字无意义 """
 98         """ x[y:z] <==> x[y.__index__():z.__index__()] """
 99         pass
100 
101     def __init__(self, x, base=10): # known special case of int.__init__
102         """ 构造方法,执行 x = 123 或 x = int(10) 时,自动调用,暂时忽略 """ 
103         """
104         int(x=0) -> int or long
105         int(x, base=10) -> int or long
106         
107         Convert a number or string to an integer, or return 0 if no arguments
108         are given.  If x is floating point, the conversion truncates towards zero.
109         If x is outside the integer range, the function returns a long instead.
110         
111         If x is not a number or if base is given, then x must be a string or
112         Unicode object representing an integer literal in the given base.  The
113         literal can be preceded by '+' or '-' and be surrounded by whitespace.
114         The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
115         interpret the base from the string as an integer literal.
116         >>> int('0b100', base=0)
117         # (copied from class doc)
118         """
119         pass
120 
121     def __int__(self): 
122         """ 转换为整数 """ 
123         """ x.__int__() <==> int(x) """
124         pass
125 
126     def __invert__(self): 
127         """ x.__invert__() <==> ~x """
128         pass
129 
130     def __long__(self): 
131         """ 转换为长整数 """ 
132         """ x.__long__() <==> long(x) """
133         pass
134 
135     def __lshift__(self, y): 
136         """ x.__lshift__(y) <==> x<<y """
137         pass
138 
139     def __mod__(self, y): 
140         """ x.__mod__(y) <==> x%y """
141         pass
142 
143     def __mul__(self, y): 
144         """ x.__mul__(y) <==> x*y """
145         pass
146 
147     def __neg__(self): 
148         """ x.__neg__() <==> -x """
149         pass
150 
151     @staticmethod # known case of __new__
152     def __new__(S, *more): 
153         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
154         pass
155 
156     def __nonzero__(self): 
157         """ x.__nonzero__() <==> x != 0 """
158         pass
159 
160     def __oct__(self): 
161         """ 返回改值的 八进制 表示 """ 
162         """ x.__oct__() <==> oct(x) """
163         pass
164 
165     def __or__(self, y): 
166         """ x.__or__(y) <==> x|y """
167         pass
168 
169     def __pos__(self): 
170         """ x.__pos__() <==> +x """
171         pass
172 
173     def __pow__(self, y, z=None): 
174         """ 幂,次方 """ 
175         """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
176         pass
177 
178     def __radd__(self, y): 
179         """ x.__radd__(y) <==> y+x """
180         pass
181 
182     def __rand__(self, y): 
183         """ x.__rand__(y) <==> y&x """
184         pass
185 
186     def __rdivmod__(self, y): 
187         """ x.__rdivmod__(y) <==> divmod(y, x) """
188         pass
189 
190     def __rdiv__(self, y): 
191         """ x.__rdiv__(y) <==> y/x """
192         pass
193 
194     def __repr__(self): 
195         """转化为解释器可读取的形式 """
196         """ x.__repr__() <==> repr(x) """
197         pass
198 
199     def __str__(self): 
200         """转换为人阅读的形式,如果没有适于人阅读的解释形式的话,则返回解释器课阅读的形式"""
201         """ x.__str__() <==> str(x) """
202         pass
203 
204     def __rfloordiv__(self, y): 
205         """ x.__rfloordiv__(y) <==> y//x """
206         pass
207 
208     def __rlshift__(self, y): 
209         """ x.__rlshift__(y) <==> y<<x """
210         pass
211 
212     def __rmod__(self, y): 
213         """ x.__rmod__(y) <==> y%x """
214         pass
215 
216     def __rmul__(self, y): 
217         """ x.__rmul__(y) <==> y*x """
218         pass
219 
220     def __ror__(self, y): 
221         """ x.__ror__(y) <==> y|x """
222         pass
223 
224     def __rpow__(self, x, z=None): 
225         """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
226         pass
227 
228     def __rrshift__(self, y): 
229         """ x.__rrshift__(y) <==> y>>x """
230         pass
231 
232     def __rshift__(self, y): 
233         """ x.__rshift__(y) <==> x>>y """
234         pass
235 
236     def __rsub__(self, y): 
237         """ x.__rsub__(y) <==> y-x """
238         pass
239 
240     def __rtruediv__(self, y): 
241         """ x.__rtruediv__(y) <==> y/x """
242         pass
243 
244     def __rxor__(self, y): 
245         """ x.__rxor__(y) <==> y^x """
246         pass
247 
248     def __sub__(self, y): 
249         """ x.__sub__(y) <==> x-y """
250         pass
251 
252     def __truediv__(self, y): 
253         """ x.__truediv__(y) <==> x/y """
254         pass
255 
256     def __trunc__(self, *args, **kwargs): 
257         """ 返回数值被截取为整形的值,在整形中无意义 """
258         pass
259 
260     def __xor__(self, y): 
261         """ x.__xor__(y) <==> x^y """
262         pass
263 
264     denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
265     """ 分母 = 1 """
266     """the denominator of a rational number in lowest terms"""
267 
268     imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
269     """ 虚数,无意义 """
270     """the imaginary part of a complex number"""
271 
272     numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
273     """ 分子 = 数字大小 """
274     """the numerator of a rational number in lowest terms"""
275 
276     real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
277     """ 实属,无意义 """
278     """the real part of a complex number"""
279 
280 int
int
 1 站点分页:
 2 数据库共95条,每页显示10条数据
 3 
 4 几页
 5 
 6 1、95/10
 7 2、余数 95%10
 8 
 9 if 余数>0
10    95/10 +1
11 else:
12    95/10
demo
1 all_item = 95
2 pager = 10
3 result = all_item._divmod_(10)
4 print result
View Code

8.float和long内部功能

float:

如:3.14、  每个浮点型都具备如下功能:

  1 class float(object):
  2     """
  3     float(x) -> floating point number
  4     
  5     Convert a string or number to a floating point number, if possible.
  6     """
  7     def as_integer_ratio(self): # real signature unknown; restored from __doc__
  8         """
  9         float.as_integer_ratio() -> (int, int)
 10         
 11         Return a pair of integers, whose ratio is exactly equal to the original
 12         float and with a positive denominator.
 13         Raise OverflowError on infinities and a ValueError on NaNs.
 14         
 15         >>> (10.0).as_integer_ratio()
 16         (10, 1)
 17         >>> (0.0).as_integer_ratio()
 18         (0, 1)
 19         >>> (-.25).as_integer_ratio()
 20         (-1, 4)
 21         """
 22         pass
 23 
 24     def conjugate(self, *args, **kwargs): # real signature unknown
 25         """ Return self, the complex conjugate of any float. """
 26         pass
 27 
 28     def fromhex(self, string): # real signature unknown; restored from __doc__
 29         """
 30         float.fromhex(string) -> float
 31         
 32         Create a floating-point number from a hexadecimal string.
 33         >>> float.fromhex('0x1.ffffp10')
 34         2047.984375
 35         >>> float.fromhex('-0x1p-1074')
 36         -5e-324
 37         """
 38         return 0.0
 39 
 40     def hex(self): # real signature unknown; restored from __doc__
 41         """
 42         float.hex() -> string
 43         
 44         Return a hexadecimal representation of a floating-point number.
 45         >>> (-0.1).hex()
 46         '-0x1.999999999999ap-4'
 47         >>> 3.14159.hex()
 48         '0x1.921f9f01b866ep+1'
 49         """
 50         return ""
 51 
 52     def is_integer(self, *args, **kwargs): # real signature unknown
 53         """ Return True if the float is an integer. """
 54         pass
 55 
 56     def __abs__(self, *args, **kwargs): # real signature unknown
 57         """ abs(self) """
 58         pass
 59 
 60     def __add__(self, *args, **kwargs): # real signature unknown
 61         """ Return self+value. """
 62         pass
 63 
 64     def __bool__(self, *args, **kwargs): # real signature unknown
 65         """ self != 0 """
 66         pass
 67 
 68     def __divmod__(self, *args, **kwargs): # real signature unknown
 69         """ Return divmod(self, value). """
 70         pass
 71 
 72     def __eq__(self, *args, **kwargs): # real signature unknown
 73         """ Return self==value. """
 74         pass
 75 
 76     def __float__(self, *args, **kwargs): # real signature unknown
 77         """ float(self) """
 78         pass
 79 
 80     def __floordiv__(self, *args, **kwargs): # real signature unknown
 81         """ Return self//value. """
 82         pass
 83 
 84     def __format__(self, format_spec): # real signature unknown; restored from __doc__
 85         """
 86         float.__format__(format_spec) -> string
 87         
 88         Formats the float according to format_spec.
 89         """
 90         return ""
 91 
 92     def __getattribute__(self, *args, **kwargs): # real signature unknown
 93         """ Return getattr(self, name). """
 94         pass
 95 
 96     def __getformat__(self, typestr): # real signature unknown; restored from __doc__
 97         """
 98         float.__getformat__(typestr) -> string
 99         
100         You probably don't want to use this function.  It exists mainly to be
101         used in Python's test suite.
102         
103         typestr must be 'double' or 'float'.  This function returns whichever of
104         'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the
105         format of floating point numbers used by the C type named by typestr.
106         """
107         return ""
108 
109     def __getnewargs__(self, *args, **kwargs): # real signature unknown
110         pass
111 
112     def __ge__(self, *args, **kwargs): # real signature unknown
113         """ Return self>=value. """
114         pass
115 
116     def __gt__(self, *args, **kwargs): # real signature unknown
117         """ Return self>value. """
118         pass
119 
120     def __hash__(self, *args, **kwargs): # real signature unknown
121         """ Return hash(self). """
122         pass
123 
124     def __init__(self, x): # real signature unknown; restored from __doc__
125         pass
126 
127     def __int__(self, *args, **kwargs): # real signature unknown
128         """ int(self) """
129         pass
130 
131     def __le__(self, *args, **kwargs): # real signature unknown
132         """ Return self<=value. """
133         pass
134 
135     def __lt__(self, *args, **kwargs): # real signature unknown
136         """ Return self<value. """
137         pass
138 
139     def __mod__(self, *args, **kwargs): # real signature unknown
140         """ Return self%value. """
141         pass
142 
143     def __mul__(self, *args, **kwargs): # real signature unknown
144         """ Return self*value. """
145         pass
146 
147     def __neg__(self, *args, **kwargs): # real signature unknown
148         """ -self """
149         pass
150 
151     @staticmethod # known case of __new__
152     def __new__(*args, **kwargs): # real signature unknown
153         """ Create and return a new object.  See help(type) for accurate signature. """
154         pass
155 
156     def __ne__(self, *args, **kwargs): # real signature unknown
157         """ Return self!=value. """
158         pass
159 
160     def __pos__(self, *args, **kwargs): # real signature unknown
161         """ +self """
162         pass
163 
164     def __pow__(self, *args, **kwargs): # real signature unknown
165         """ Return pow(self, value, mod). """
166         pass
167 
168     def __radd__(self, *args, **kwargs): # real signature unknown
169         """ Return value+self. """
170         pass
171 
172     def __rdivmod__(self, *args, **kwargs): # real signature unknown
173         """ Return divmod(value, self). """
174         pass
175 
176     def __repr__(self, *args, **kwargs): # real signature unknown
177         """ Return repr(self). """
178         pass
179 
180     def __rfloordiv__(self, *args, **kwargs): # real signature unknown
181         """ Return value//self. """
182         pass
183 
184     def __rmod__(self, *args, **kwargs): # real signature unknown
185         """ Return value%self. """
186         pass
187 
188     def __rmul__(self, *args, **kwargs): # real signature unknown
189         """ Return value*self. """
190         pass
191 
192     def __round__(self, *args, **kwargs): # real signature unknown
193         """
194         Return the Integral closest to x, rounding half toward even.
195         When an argument is passed, work like built-in round(x, ndigits).
196         """
197         pass
198 
199     def __rpow__(self, *args, **kwargs): # real signature unknown
200         """ Return pow(value, self, mod). """
201         pass
202 
203     def __rsub__(self, *args, **kwargs): # real signature unknown
204         """ Return value-self. """
205         pass
206 
207     def __rtruediv__(self, *args, **kwargs): # real signature unknown
208         """ Return value/self. """
209         pass
210 
211     def __setformat__(self, typestr, fmt): # real signature unknown; restored from __doc__
212         """
213         float.__setformat__(typestr, fmt) -> None
214         
215         You probably don't want to use this function.  It exists mainly to be
216         used in Python's test suite.
217         
218         typestr must be 'double' or 'float'.  fmt must be one of 'unknown',
219         'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be
220         one of the latter two if it appears to match the underlying C reality.
221         
222         Override the automatic determination of C-level floating point type.
223         This affects how floats are converted to and from binary strings.
224         """
225         pass
226 
227     def __str__(self, *args, **kwargs): # real signature unknown
228         """ Return str(self). """
229         pass
230 
231     def __sub__(self, *args, **kwargs): # real signature unknown
232         """ Return self-value. """
233         pass
234 
235     def __truediv__(self, *args, **kwargs): # real signature unknown
236         """ Return self/value. """
237         pass
238 
239     def __trunc__(self, *args, **kwargs): # real signature unknown
240         """ Return the Integral closest to x between 0 and x. """
241         pass
242 
243     imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
244     """the imaginary part of a complex number"""
245 
246     real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
247     """the real part of a complex number"""
class float(object)

long:

可能如:2147483649、9223372036854775807

每个长整型都具备如下功能:

  1 class long(object):
  2     """
  3     long(x=0) -> long
  4     long(x, base=10) -> long
  5     
  6     Convert a number or string to a long integer, or return 0L if no arguments
  7     are given.  If x is floating point, the conversion truncates towards zero.
  8     
  9     If x is not a number or if base is given, then x must be a string or
 10     Unicode object representing an integer literal in the given base.  The
 11     literal can be preceded by '+' or '-' and be surrounded by whitespace.
 12     The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
 13     interpret the base from the string as an integer literal.
 14     >>> int('0b100', base=0)
 15     4L
 16     """
 17     def bit_length(self): # real signature unknown; restored from __doc__
 18         """
 19         long.bit_length() -> int or long
 20         
 21         Number of bits necessary to represent self in binary.
 22         >>> bin(37L)
 23         '0b100101'
 24         >>> (37L).bit_length()
 25         """
 26         return 0
 27 
 28     def conjugate(self, *args, **kwargs): # real signature unknown
 29         """ Returns self, the complex conjugate of any long. """
 30         pass
 31 
 32     def __abs__(self): # real signature unknown; restored from __doc__
 33         """ x.__abs__() <==> abs(x) """
 34         pass
 35 
 36     def __add__(self, y): # real signature unknown; restored from __doc__
 37         """ x.__add__(y) <==> x+y """
 38         pass
 39 
 40     def __and__(self, y): # real signature unknown; restored from __doc__
 41         """ x.__and__(y) <==> x&y """
 42         pass
 43 
 44     def __cmp__(self, y): # real signature unknown; restored from __doc__
 45         """ x.__cmp__(y) <==> cmp(x,y) """
 46         pass
 47 
 48     def __coerce__(self, y): # real signature unknown; restored from __doc__
 49         """ x.__coerce__(y) <==> coerce(x, y) """
 50         pass
 51 
 52     def __divmod__(self, y): # real signature unknown; restored from __doc__
 53         """ x.__divmod__(y) <==> divmod(x, y) """
 54         pass
 55 
 56     def __div__(self, y): # real signature unknown; restored from __doc__
 57         """ x.__div__(y) <==> x/y """
 58         pass
 59 
 60     def __float__(self): # real signature unknown; restored from __doc__
 61         """ x.__float__() <==> float(x) """
 62         pass
 63 
 64     def __floordiv__(self, y): # real signature unknown; restored from __doc__
 65         """ x.__floordiv__(y) <==> x//y """
 66         pass
 67 
 68     def __format__(self, *args, **kwargs): # real signature unknown
 69         pass
 70 
 71     def __getattribute__(self, name): # real signature unknown; restored from __doc__
 72         """ x.__getattribute__('name') <==> x.name """
 73         pass
 74 
 75     def __getnewargs__(self, *args, **kwargs): # real signature unknown
 76         pass
 77 
 78     def __hash__(self): # real signature unknown; restored from __doc__
 79         """ x.__hash__() <==> hash(x) """
 80         pass
 81 
 82     def __hex__(self): # real signature unknown; restored from __doc__
 83         """ x.__hex__() <==> hex(x) """
 84         pass
 85 
 86     def __index__(self): # real signature unknown; restored from __doc__
 87         """ x[y:z] <==> x[y.__index__():z.__index__()] """
 88         pass
 89 
 90     def __init__(self, x=0): # real signature unknown; restored from __doc__
 91         pass
 92 
 93     def __int__(self): # real signature unknown; restored from __doc__
 94         """ x.__int__() <==> int(x) """
 95         pass
 96 
 97     def __invert__(self): # real signature unknown; restored from __doc__
 98         """ x.__invert__() <==> ~x """
 99         pass
100 
101     def __long__(self): # real signature unknown; restored from __doc__
102         """ x.__long__() <==> long(x) """
103         pass
104 
105     def __lshift__(self, y): # real signature unknown; restored from __doc__
106         """ x.__lshift__(y) <==> x<<y """
107         pass
108 
109     def __mod__(self, y): # real signature unknown; restored from __doc__
110         """ x.__mod__(y) <==> x%y """
111         pass
112 
113     def __mul__(self, y): # real signature unknown; restored from __doc__
114         """ x.__mul__(y) <==> x*y """
115         pass
116 
117     def __neg__(self): # real signature unknown; restored from __doc__
118         """ x.__neg__() <==> -x """
119         pass
120 
121     @staticmethod # known case of __new__
122     def __new__(S, *more): # real signature unknown; restored from __doc__
123         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
124         pass
125 
126     def __nonzero__(self): # real signature unknown; restored from __doc__
127         """ x.__nonzero__() <==> x != 0 """
128         pass
129 
130     def __oct__(self): # real signature unknown; restored from __doc__
131         """ x.__oct__() <==> oct(x) """
132         pass
133 
134     def __or__(self, y): # real signature unknown; restored from __doc__
135         """ x.__or__(y) <==> x|y """
136         pass
137 
138     def __pos__(self): # real signature unknown; restored from __doc__
139         """ x.__pos__() <==> +x """
140         pass
141 
142     def __pow__(self, y, z=None): # real signature unknown; restored from __doc__
143         """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
144         pass
145 
146     def __radd__(self, y): # real signature unknown; restored from __doc__
147         """ x.__radd__(y) <==> y+x """
148         pass
149 
150     def __rand__(self, y): # real signature unknown; restored from __doc__
151         """ x.__rand__(y) <==> y&x """
152         pass
153 
154     def __rdivmod__(self, y): # real signature unknown; restored from __doc__
155         """ x.__rdivmod__(y) <==> divmod(y, x) """
156         pass
157 
158     def __rdiv__(self, y): # real signature unknown; restored from __doc__
159         """ x.__rdiv__(y) <==> y/x """
160         pass
161 
162     def __repr__(self): # real signature unknown; restored from __doc__
163         """ x.__repr__() <==> repr(x) """
164         pass
165 
166     def __rfloordiv__(self, y): # real signature unknown; restored from __doc__
167         """ x.__rfloordiv__(y) <==> y//x """
168         pass
169 
170     def __rlshift__(self, y): # real signature unknown; restored from __doc__
171         """ x.__rlshift__(y) <==> y<<x """
172         pass
173 
174     def __rmod__(self, y): # real signature unknown; restored from __doc__
175         """ x.__rmod__(y) <==> y%x """
176         pass
177 
178     def __rmul__(self, y): # real signature unknown; restored from __doc__
179         """ x.__rmul__(y) <==> y*x """
180         pass
181 
182     def __ror__(self, y): # real signature unknown; restored from __doc__
183         """ x.__ror__(y) <==> y|x """
184         pass
185 
186     def __rpow__(self, x, z=None): # real signature unknown; restored from __doc__
187         """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
188         pass
189 
190     def __rrshift__(self, y): # real signature unknown; restored from __doc__
191         """ x.__rrshift__(y) <==> y>>x """
192         pass
193 
194     def __rshift__(self, y): # real signature unknown; restored from __doc__
195         """ x.__rshift__(y) <==> x>>y """
196         pass
197 
198     def __rsub__(self, y): # real signature unknown; restored from __doc__
199         """ x.__rsub__(y) <==> y-x """
200         pass
201 
202     def __rtruediv__(self, y): # real signature unknown; restored from __doc__
203         """ x.__rtruediv__(y) <==> y/x """
204         pass
205 
206     def __rxor__(self, y): # real signature unknown; restored from __doc__
207         """ x.__rxor__(y) <==> y^x """
208         pass
209 
210     def __sizeof__(self, *args, **kwargs): # real signature unknown
211         """ Returns size in memory, in bytes """
212         pass
213 
214     def __str__(self): # real signature unknown; restored from __doc__
215         """ x.__str__() <==> str(x) """
216         pass
217 
218     def __sub__(self, y): # real signature unknown; restored from __doc__
219         """ x.__sub__(y) <==> x-y """
220         pass
221 
222     def __truediv__(self, y): # real signature unknown; restored from __doc__
223         """ x.__truediv__(y) <==> x/y """
224         pass
225 
226     def __trunc__(self, *args, **kwargs): # real signature unknown
227         """ Truncating an Integral returns itself. """
228         pass
229 
230     def __xor__(self, y): # real signature unknown; restored from __doc__
231         """ x.__xor__(y) <==> x^y """
232         pass
233 
234     denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
235     """the denominator of a rational number in lowest terms"""
236 
237     imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
238     """the imaginary part of a complex number"""
239 
240     numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
241     """the numerator of a rational number in lowest terms"""
242 
243     real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
244     """the real part of a complex number"""
245 
246 long
long

9.str内部功能介绍

  1 class str(object):
  2     """
  3     str(object='') -> str
  4     str(bytes_or_buffer[, encoding[, errors]]) -> str
  5     
  6     Create a new string object from the given object. If encoding or
  7     errors is specified, then the object must expose a data buffer
  8     that will be decoded using the given encoding and error handler.
  9     Otherwise, returns the result of object.__str__() (if defined)
 10     or repr(object).
 11     encoding defaults to sys.getdefaultencoding().
 12     errors defaults to 'strict'.
 13     """
 14     def capitalize(self): # real signature unknown; restored from __doc__
 15         """
 16         S.capitalize() -> str
 17         
 18         Return a capitalized version of S, i.e. make the first character
 19         have upper case and the rest lower case.
 20         """
 21         return ""
 22 
 23     def casefold(self): # real signature unknown; restored from __doc__
 24         """
 25         S.casefold() -> str
 26         
 27         Return a version of S suitable for caseless comparisons.
 28         """
 29         return ""
 30 
 31     def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
 32         """
 33         S.center(width[, fillchar]) -> str
 34         
 35         Return S centered in a string of length width. Padding is
 36         done using the specified fill character (default is a space)
 37         """
 38         return ""
 39 
 40     def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
 41         """
 42         S.count(sub[, start[, end]]) -> int
 43         
 44         Return the number of non-overlapping occurrences of substring sub in
 45         string S[start:end].  Optional arguments start and end are
 46         interpreted as in slice notation.
 47         """
 48         return 0
 49 
 50     def encode(self, encoding='utf-8', errors='strict'): # real signature unknown; restored from __doc__
 51         """
 52         S.encode(encoding='utf-8', errors='strict') -> bytes
 53         
 54         Encode S using the codec registered for encoding. Default encoding
 55         is 'utf-8'. errors may be given to set a different error
 56         handling scheme. Default is 'strict' meaning that encoding errors raise
 57         a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
 58         'xmlcharrefreplace' as well as any other name registered with
 59         codecs.register_error that can handle UnicodeEncodeErrors.
 60         """
 61         return b""
 62 
 63     def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
 64         """
 65         S.endswith(suffix[, start[, end]]) -> bool
 66         
 67         Return True if S ends with the specified suffix, False otherwise.
 68         With optional start, test S beginning at that position.
 69         With optional end, stop comparing S at that position.
 70         suffix can also be a tuple of strings to try.
 71         """
 72         return False
 73 
 74     def expandtabs(self, tabsize=8): # real signature unknown; restored from __doc__
 75         """
 76         S.expandtabs(tabsize=8) -> str
 77         
 78         Return a copy of S where all tab characters are expanded using spaces.
 79         If tabsize is not given, a tab size of 8 characters is assumed.
 80         """
 81         return ""
 82 
 83     def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
 84         """
 85         S.find(sub[, start[, end]]) -> int
 86         
 87         Return the lowest index in S where substring sub is found,
 88         such that sub is contained within S[start:end].  Optional
 89         arguments start and end are interpreted as in slice notation.
 90         
 91         Return -1 on failure.
 92         """
 93         return 0
 94 
 95     def format(*args, **kwargs): # known special case of str.format
 96         """
 97         S.format(*args, **kwargs) -> str
 98         
 99         Return a formatted version of S, using substitutions from args and kwargs.
100         The substitutions are identified by braces ('{' and '}').
101         """
102         pass
103 
104     def format_map(self, mapping): # real signature unknown; restored from __doc__
105         """
106         S.format_map(mapping) -> str
107         
108         Return a formatted version of S, using substitutions from mapping.
109         The substitutions are identified by braces ('{' and '}').
110         """
111         return ""
112 
113     def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
114         """
115         S.index(sub[, start[, end]]) -> int
116         
117         Like S.find() but raise ValueError when the substring is not found.
118         """
119         return 0
120 
121     def isalnum(self): # real signature unknown; restored from __doc__
122         """
123         S.isalnum() -> bool
124         
125         Return True if all characters in S are alphanumeric
126         and there is at least one character in S, False otherwise.
127         """
128         return False
129 
130     def isalpha(self): # real signature unknown; restored from __doc__
131         """
132         S.isalpha() -> bool
133         
134         Return True if all characters in S are alphabetic
135         and there is at least one character in S, False otherwise.
136         """
137         return False
138 
139     def isdecimal(self): # real signature unknown; restored from __doc__
140         """
141         S.isdecimal() -> bool
142         
143         Return True if there are only decimal characters in S,
144         False otherwise.
145         """
146         return False
147 
148     def isdigit(self): # real signature unknown; restored from __doc__
149         """
150         S.isdigit() -> bool
151         
152         Return True if all characters in S are digits
153         and there is at least one character in S, False otherwise.
154         """
155         return False
156 
157     def isidentifier(self): # real signature unknown; restored from __doc__
158         """
159         S.isidentifier() -> bool
160         
161         Return True if S is a valid identifier according
162         to the language definition.
163         
164         Use keyword.iskeyword() to test for reserved identifiers
165         such as "def" and "class".
166         """
167         return False
168 
169     def islower(self): # real signature unknown; restored from __doc__
170         """
171         S.islower() -> bool
172         
173         Return True if all cased characters in S are lowercase and there is
174         at least one cased character in S, False otherwise.
175         """
176         return False
177 
178     def isnumeric(self): # real signature unknown; restored from __doc__
179         """
180         S.isnumeric() -> bool
181         
182         Return True if there are only numeric characters in S,
183         False otherwise.
184         """
185         return False
186 
187     def isprintable(self): # real signature unknown; restored from __doc__
188         """
189         S.isprintable() -> bool
190         
191         Return True if all characters in S are considered
192         printable in repr() or S is empty, False otherwise.
193         """
194         return False
195 
196     def isspace(self): # real signature unknown; restored from __doc__
197         """
198         S.isspace() -> bool
199         
200         Return True if all characters in S are whitespace
201         and there is at least one character in S, False otherwise.
202         """
203         return False
204 
205     def istitle(self): # real signature unknown; restored from __doc__
206         """
207         S.istitle() -> bool
208         
209         Return True if S is a titlecased string and there is at least one
210         character in S, i.e. upper- and titlecase characters may only
211         follow uncased characters and lowercase characters only cased ones.
212         Return False otherwise.
213         """
214         return False
215 
216     def isupper(self): # real signature unknown; restored from __doc__
217         """
218         S.isupper() -> bool
219         
220         Return True if all cased characters in S are uppercase and there is
221         at least one cased character in S, False otherwise.
222         """
223         return False
224 
225     def join(self, iterable): # real signature unknown; restored from __doc__
226         """
227         S.join(iterable) -> str
228         
229         Return a string which is the concatenation of the strings in the
230         iterable.  The separator between elements is S.
231         """
232         return ""
233 
234     def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
235         """
236         S.ljust(width[, fillchar]) -> str
237         
238         Return S left-justified in a Unicode string of length width. Padding is
239         done using the specified fill character (default is a space).
240         """
241         return ""
242 
243     def lower(self): # real signature unknown; restored from __doc__
244         """
245         S.lower() -> str
246         
247         Return a copy of the string S converted to lowercase.
248         """
249         return ""
250 
251     def lstrip(self, chars=None): # real signature unknown; restored from __doc__
252         """
253         S.lstrip([chars]) -> str
254         
255         Return a copy of the string S with leading whitespace removed.
256         If chars is given and not None, remove characters in chars instead.
257         """
258         return ""
259 
260     def maketrans(self, *args, **kwargs): # real signature unknown
261         """
262         Return a translation table usable for str.translate().
263         
264         If there is only one argument, it must be a dictionary mapping Unicode
265         ordinals (integers) or characters to Unicode ordinals, strings or None.
266         Character keys will be then converted to ordinals.
267         If there are two arguments, they must be strings of equal length, and
268         in the resulting dictionary, each character in x will be mapped to the
269         character at the same position in y. If there is a third argument, it
270         must be a string, whose characters will be mapped to None in the result.
271         """
272         pass
273 
274     def partition(self, sep): # real signature unknown; restored from __doc__
275         """
276         S.partition(sep) -> (head, sep, tail)
277         
278         Search for the separator sep in S, and return the part before it,
279         the separator itself, and the part after it.  If the separator is not
280         found, return S and two empty strings.
281         """
282         pass
283 
284     def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
285         """
286         S.replace(old, new[, count]) -> str
287         
288         Return a copy of S with all occurrences of substring
289         old replaced by new.  If the optional argument count is
290         given, only the first count occurrences are replaced.
291         """
292         return ""
293 
294     def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
295         """
296         S.rfind(sub[, start[, end]]) -> int
297         
298         Return the highest index in S where substring sub is found,
299         such that sub is contained within S[start:end].  Optional
300         arguments start and end are interpreted as in slice notation.
301         
302         Return -1 on failure.
303         """
304         return 0
305 
306     def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
307         """
308         S.rindex(sub[, start[, end]]) -> int
309         
310         Like S.rfind() but raise ValueError when the substring is not found.
311         """
312         return 0
313 
314     def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
315         """
316         S.rjust(width[, fillchar]) -> str
317         
318         Return S right-justified in a string of length width. Padding is
319         done using the specified fill character (default is a space).
320         """
321         return ""
322 
323     def rpartition(self, sep): # real signature unknown; restored from __doc__
324         """
325         S.rpartition(sep) -> (head, sep, tail)
326         
327         Search for the separator sep in S, starting at the end of S, and return
328         the part before it, the separator itself, and the part after it.  If the
329         separator is not found, return two empty strings and S.
330         """
331         pass
332 
333     def rsplit(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
334         """
335         S.rsplit(sep=None, maxsplit=-1) -> list of strings
336         
337         Return a list of the words in S, using sep as the
338         delimiter string, starting at the end of the string and
339         working to the front.  If maxsplit is given, at most maxsplit
340         splits are done. If sep is not specified, any whitespace string
341         is a separator.
342         """
343         return []
344 
345     def rstrip(self, chars=None): # real signature unknown; restored from __doc__
346         """
347         S.rstrip([chars]) -> str
348         
349         Return a copy of the string S with trailing whitespace removed.
350         If chars is given and not None, remove characters in chars instead.
351         """
352         return ""
353 
354     def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
355         """
356         S.split(sep=None, maxsplit=-1) -> list of strings
357         
358         Return a list of the words in S, using sep as the
359         delimiter string.  If maxsplit is given, at most maxsplit
360         splits are done. If sep is not specified or is None, any
361         whitespace string is a separator and empty strings are
362         removed from the result.
363         """
364         return []
365 
366     def splitlines(self, keepends=None): # real signature unknown; restored from __doc__
367         """
368         S.splitlines([keepends]) -> list of strings
369         
370         Return a list of the lines in S, breaking at line boundaries.
371         Line breaks are not included in the resulting list unless keepends
372         is given and true.
373         """
374         return []
375 
376     def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
377         """
378         S.startswith(prefix[, start[, end]]) -> bool
379         
380         Return True if S starts with the specified prefix, False otherwise.
381         With optional start, test S beginning at that position.
382         With optional end, stop comparing S at that position.
383         prefix can also be a tuple of strings to try.
384         """
385         return False
386 
387     def strip(self, chars=None): # real signature unknown; restored from __doc__
388         """
389         S.strip([chars]) -> str
390         
391         Return a copy of the string S with leading and trailing
392         whitespace removed.
393         If chars is given and not None, remove characters in chars instead.
394         """
395         return ""
396 
397     def swapcase(self): # real signature unknown; restored from __doc__
398         """
399         S.swapcase() -> str
400         
401         Return a copy of S with uppercase characters converted to lowercase
402         and vice versa.
403         """
404         return ""
405 
406     def title(self): # real signature unknown; restored from __doc__
407         """
408         S.title() -> str
409         
410         Return a titlecased version of S, i.e. words start with title case
411         characters, all remaining cased characters have lower case.
412         """
413         return ""
414 
415     def translate(self, table): # real signature unknown; restored from __doc__
416         """
417         S.translate(table) -> str
418         
419         Return a copy of the string S in which each character has been mapped
420         through the given translation table. The table must implement
421         lookup/indexing via __getitem__, for instance a dictionary or list,
422         mapping Unicode ordinals to Unicode ordinals, strings, or None. If
423         this operation raises LookupError, the character is left untouched.
424         Characters mapped to None are deleted.
425         """
426         return ""
427 
428     def upper(self): # real signature unknown; restored from __doc__
429         """
430         S.upper() -> str
431         
432         Return a copy of S converted to uppercase.
433         """
434         return ""
435 
436     def zfill(self, width): # real signature unknown; restored from __doc__
437         """
438         S.zfill(width) -> str
439         
440         Pad a numeric string S with zeros on the left, to fill a field
441         of the specified width. The string S is never truncated.
442         """
443         return ""
444 
445     def __add__(self, *args, **kwargs): # real signature unknown
446         """ Return self+value. """
447         pass
448 
449     def __contains__(self, *args, **kwargs): # real signature unknown
450         """ Return key in self. """
451         pass
452 
453     def __eq__(self, *args, **kwargs): # real signature unknown
454         """ Return self==value. """
455         pass
456 
457     def __format__(self, format_spec): # real signature unknown; restored from __doc__
458         """
459         S.__format__(format_spec) -> str
460         
461         Return a formatted version of S as described by format_spec.
462         """
463         return ""
464 
465     def __getattribute__(self, *args, **kwargs): # real signature unknown
466         """ Return getattr(self, name). """
467         pass
468 
469     def __getitem__(self, *args, **kwargs): # real signature unknown
470         """ Return self[key]. """
471         pass
472 
473     def __getnewargs__(self, *args, **kwargs): # real signature unknown
474         pass
475 
476     def __ge__(self, *args, **kwargs): # real signature unknown
477         """ Return self>=value. """
478         pass
479 
480     def __gt__(self, *args, **kwargs): # real signature unknown
481         """ Return self>value. """
482         pass
483 
484     def __hash__(self, *args, **kwargs): # real signature unknown
485         """ Return hash(self). """
486         pass
487 
488     def __init__(self, value='', encoding=None, errors='strict'): # known special case of str.__init__
489         """
490         str(object='') -> str
491         str(bytes_or_buffer[, encoding[, errors]]) -> str
492         
493         Create a new string object from the given object. If encoding or
494         errors is specified, then the object must expose a data buffer
495         that will be decoded using the given encoding and error handler.
496         Otherwise, returns the result of object.__str__() (if defined)
497         or repr(object).
498         encoding defaults to sys.getdefaultencoding().
499         errors defaults to 'strict'.
500         # (copied from class doc)
501         """
502         pass
503 
504     def __iter__(self, *args, **kwargs): # real signature unknown
505         """ Implement iter(self). """
506         pass
507 
508     def __len__(self, *args, **kwargs): # real signature unknown
509         """ Return len(self). """
510         pass
511 
512     def __le__(self, *args, **kwargs): # real signature unknown
513         """ Return self<=value. """
514         pass
515 
516     def __lt__(self, *args, **kwargs): # real signature unknown
517         """ Return self<value. """
518         pass
519 
520     def __mod__(self, *args, **kwargs): # real signature unknown
521         """ Return self%value. """
522         pass
523 
524     def __mul__(self, *args, **kwargs): # real signature unknown
525         """ Return self*value.n """
526         pass
527 
528     @staticmethod # known case of __new__
529     def __new__(*args, **kwargs): # real signature unknown
530         """ Create and return a new object.  See help(type) for accurate signature. """
531         pass
532 
533     def __ne__(self, *args, **kwargs): # real signature unknown
534         """ Return self!=value. """
535         pass
536 
537     def __repr__(self, *args, **kwargs): # real signature unknown
538         """ Return repr(self). """
539         pass
540 
541     def __rmod__(self, *args, **kwargs): # real signature unknown
542         """ Return value%self. """
543         pass
544 
545     def __rmul__(self, *args, **kwargs): # real signature unknown
546         """ Return self*value. """
547         pass
548 
549     def __sizeof__(self): # real signature unknown; restored from __doc__
550         """ S.__sizeof__() -> size of S in memory, in bytes """
551         pass
552 
553     def __str__(self, *args, **kwargs): # real signature unknown
554         """ Return str(self). """
555         pass
class str(object)
#! /usr/bin/env python
# -*- coding:utf-8 -*-
"""
name = 'jack'
name = str('jack') #str类的__init__
print(type(name))
print(dir(name))
输出:
<class 'str'>
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
result = name.__contains__('jack')
print(result)
# 等于 result = 'jack' in name
# 输出:True
"""

# 字符串格式化在3.0里
# name = 'jack{0}'
# name.__format__("leon")
# print(name)

dic = {'k1':'v1','k2':'v2'}
# dic['k1']  取值__getitem__

name = 'jack'
a = name.capitalize()
print(a)
# 输出:Jack   即首字母大写

name = 'Jack'
a = name.casefold()
print(a)
# 输出:jack   即首字母小写

print("************welcome***********************")
print(8*'*')  # 即8个星号

name = 'Jack'
b = name.center(20,'*')
print(b)
# 输出:********Jack********

name = 'asdkfjalsdfjaksd'
result = name.count('sd',0,10)
print(result)  #查找起始位置,0和结束位置10 出现次数
# 输出:2

name = '李浩'
a = name.encode('gbk')
print(a)
# 输出:b'\xc0\xee\xba\xc6'  从unicode转gbk

name = 'lilei'
res = name.endswith('e',0,3)  #大于等于0小于3  取1,2位置 i l
c = name.endswith('i')
print(res,c)
# 输出:False True

name = 'kkbbbsssk'
h = name.replace('k','j')
h = name.replace('s','j',2)
print(h)

name = """
aa
bb
cc
"""
resu = name.split('\n')
print(resu)

  

10.上下文管理解析

 1 # with open('h.log') as f:
 2 #     f.write()
 3 
 4 def show():
 5     print("123")
 6     yield
 7     print("456")
 8 
 9 with show():
10     print("999")
11 
12 输出:
13 
14 123
15 999
16 456
View Code

11.list内部功能介绍

#! /usr/bin/env python
# -*- coding:utf-8 -*-

li = list([1,2,3])
libiao = list((1,2,3))
print(li,libiao)  #两种相同

# append 向列表尾部添加元素
# copy 浅拷贝
# count 元素出现次数
# extend 合并列表或元组
li.extend([222,333])
# li.extend((222,333,))  同上,记得在元组后加入一个逗号
print(li)
# 输出:[1, 2, 3, 222, 333]

# index 某个元素的索引 或下标
# insert 指定下标,插入元素
li.insert(0,'test')
print(li)
# 输出:[1, 2, 3, 222, 333]

# pop 移除某一个元素,可以加index
ret = li.pop(0)
print(li)
print(ret)  #取出拿出去的值test

a = [111,222,333,111]
a.remove(111)
print(a)  #输出:[222, 333, 111],去掉了第一个111

d = [333,22,11]
print(d)
d.reverse()  # 列表反序,输出:[11, 22, 333]
print(d)

d = [55,22,11]
d.sort()  #排序反过来
print(d)

 

12.字典简单练习

#! /usr/bin/env python
# -*- coding:utf-8 -*-

dic = {'k1':'v1','k2':'v2'}
dic = dict(k1='v1',k2='v2')

# clear 清空所有元素
# copy 浅拷贝
# fromkeys  3.0新加入,取到key,创建一个新字典
new = dic.fromkeys(['k1'],'v1')
new = dic.fromkeys(['k1','k2','k3'],'v1')
print(new)
# 输入:{'k1': 'v1', 'k2': 'v1', 'k3': 'v1'}

print(dic['k1'])
print(dic['k2'])
# print(dic['k3'])  # KeyError: 'k3'  没有k3的值

print(dic.get('k1'))
print(dic.get('k2'))
print(dic.get('k3'))
print(dic.get('k3','jack'))  #只有在key不存在的时候可以设置默认值jack
# 输出:
# v1
# v2
# None

print(dic.keys())  #输出:dict_keys(['k2', 'k1'])
print(dic.values()) #输出:dict_values(['v2', 'v1'])
print(dic.items())  #输出:dict_items([('k2', 'v2'), ('k1', 'v1')])

for k in dic.keys():
    print(k)
# 输出:
# k2
# k1

for v in dic.values():
    print(v)
# output:
# v2
# v1

for k,v in dic.items():
    print(k,v)
# output:
# k2 v2
# k1 v1

# d = dic.pop('k1')  #拿到key 1的值


# dic.popitem()  #无序随机取值
# print(dic)

dic['k3'] = 123
dic.setdefault('k4')
print(dic)
# 输出:{'k2': 'v2', 'k4': None, 'k1': 'v1', 'k3': 123}

b = {'k1':'v1','k2':'v2'}
b.update({'k2':123})
print(b)
# 输出:
# {'k2': 123, 'k1': 'v1'}

"""
练习题:
lib = [11,22,33,44,55,66,77,88,99,100]
将大于66的值放到字典的第一个key中,将小于66的放到第二个key中
即 : {'k1':'>66','k2':'<66'}
"""
# 第一种实现:
lib = [11,22,33,44,55,66,77,88,99,100]
dict_all = {}
l1 = []
l2 = []
for i in lib:
    if i > 66:
        l1.append(i)
    else:
        l2.append(i)
dict_all['k1'] = l1
dict_all['k2'] = l2
print(dict_all)
# 第二种实现

dd = {}
lib = [11,22,33,44,55,66,77,88,99,100]
for i in lib:
    if i > 66:
        if "k1" in dd.keys():
            dd['k1'].append(i)
        else:
            dd['k1'] = [i,]
    else:
        if "k2" in dd.keys():
            dd['k2'].append(i)
        else:
            dd['k2'] = [i,]
print(dd)
posted @ 2016-02-04 23:27  Leon2016  阅读(262)  评论(0编辑  收藏  举报