Day2.字典,字符串,元组,字典,集合set,类的初步认识,深浅拷贝

Posted Jason_wang_2016

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Day2.字典,字符串,元组,字典,集合set,类的初步认识,深浅拷贝相关的知识,希望对你有一定的参考价值。

Python之路【第二篇】:Python基础(一)

 

入门知识拾遗

一、作用域

对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用。

if 1==1:
name = \'JasonWang\'
print  name

下面的结论对吗?

外层变量,可以被内层变量使用
内层变量,无法被外层变量使用

二、三元运算

result = 值1 if 条件 else 值2

#三目运算符
name = \'aa\' if 1 == 2 else \'SB\'
print(name)
SB

如果条件为真:result = 值1
如果条件为假:result = 值2

三、进制

  • 二进制,01
  • 八进制,01234567
  • 十进制,0123456789
  • 十六进制,0123456789ABCDEF

Python基础

对于Python,一切事物都是对象,对象基于类创建

所以,以下这些值都是对象: "wupeiqi"、38、[\'北京\', \'上海\', \'深圳\'],并且是根据不同的类生成的对象。

一、整数

如: 18、73、84

每一个整数都具备如下功能:

 

lass int(object):
    """
    int(x=0) -> int or long
    int(x, base=10) -> int or long
    
    Convert a number or string to an integer, or return 0 if no arguments
    are given.  If x is floating point, the conversion truncates towards zero.
    If x is outside the integer range, the function returns a long instead.
    
    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)
    4
    """
    def bit_length(self): 
        """ 返回表示该数字的时占用的最少位数 """
        """
        int.bit_length() -> int
        
        Number of bits necessary to represent self in binary.
        >>> bin(37)
        \'0b100101\'
        >>> (37).bit_length()
        6
        """
        return 0

    def conjugate(self, *args, **kwargs): # real signature unknown
        """ 返回该复数的共轭复数 """
        """ Returns self, the complex conjugate of any int. """
        pass

    def __abs__(self):
        """ 返回绝对值 """
        """ x.__abs__() <==> abs(x) """
        pass

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

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

    def __cmp__(self, y): 
        """ 比较两个数大小 """
        """ x.__cmp__(y) <==> cmp(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 __float__(self): 
        """ 转换为浮点类型 """ 
        """ x.__float__() <==> float(x) """
        pass

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

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

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

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        """ 内部调用 __new__方法或创建对象时传入参数使用 """ 
        pass

    def __hash__(self): 
        """如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等。"""
        """ x.__hash__() <==> hash(x) """
        pass

    def __hex__(self): 
        """ 返回当前数的 十六进制 表示 """ 
        """ x.__hex__() <==> hex(x) """
        pass

    def __index__(self): 
        """ 用于切片,数字无意义 """
        """ x[y:z] <==> x[y.__index__():z.__index__()] """
        pass

    def __init__(self, x, base=10): # known special case of int.__init__
        """ 构造方法,执行 x = 123 或 x = int(10) 时,自动调用,暂时忽略 """ 
        """
        int(x=0) -> int or long
        int(x, base=10) -> int or long
        
        Convert a number or string to an integer, or return 0 if no arguments
        are given.  If x is floating point, the conversion truncates towards zero.
        If x is outside the integer range, the function returns a long instead.
        
        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)
        4
        # (copied from class doc)
        """
        pass

    def __int__(self): 
        """ 转换为整数 """ 
        """ x.__int__() <==> int(x) """
        pass

    def __invert__(self): 
        """ x.__invert__() <==> ~x """
        pass

    def __long__(self): 
        """ 转换为长整数 """ 
        """ x.__long__() <==> long(x) """
        pass

    def __lshift__(self, y): 
        """ x.__lshift__(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 __nonzero__(self): 
        """ x.__nonzero__() <==> x != 0 """
        pass

    def __oct__(self): 
        """ 返回改值的 八进制 表示 """ 
        """ x.__oct__() <==> oct(x) """
        pass

    def __or__(self, y): 
        """ x.__or__(y) <==> x|y """
        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 __rand__(self, y): 
        """ x.__rand__(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 __str__(self): 
        """转换为人阅读的形式,如果没有适于人阅读的解释形式的话,则返回解释器课阅读的形式"""
        """ x.__str__() <==> str(x) """
        pass

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

    def __rlshift__(self, y): 
        """ x.__rlshift__(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 __ror__(self, y): 
        """ x.__ror__(y) <==> y|x """
        pass

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

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

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

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

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

    def __rxor__(self, y): 
        """ x.__rxor__(y) <==> y^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): 
        """ 返回数值被截取为整形的值,在整形中无意义 """
        pass

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

    denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """ 分母 = 1 """
    """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"""


    
int

 

 

二、长整型

可能如: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__

以上是关于Day2.字典,字符串,元组,字典,集合set,类的初步认识,深浅拷贝的主要内容,如果未能解决你的问题,请参考以下文章

Day2 列表,元组,集合,字典

Day2-------列表元组字典等

Python之路 day2 字符串/元组/列表/字典互转

基本数据类型-集合(set)_上周内容回顾(列表_元组_集合)

python 数据类型: 数字Nubmer / 字符串String / 列表List / 元组Tuple / 集合Set / 字典Dictionary

python day2 列表 元组 字典 字符串