• Python中基本数据类型的学习


    基本数据类型

      Python中的基本数据类型分为:数字,字符串,布尔值,列表,元组,字典

    关于这些基本数据类型对象常见掉用法介绍

      数字: int

        (int型所有功能都在 int 里面,在Pychram中建立文件输入int,按住Crtl鼠标点击int 进入查看)  

    #将字符串转换为数字
    a = "123"
    b = int(a)
    #会报错转换中的字符串只能有数字
    a = "123"
    b = int(a)
    #将字符串按base进制转换为10进制
    a = "0011"
    b = int(a,base=2)
    print(b)#s输出为3
    #--bit_length()将当前数字用二进制数所表示的位数
    a = 5
    print(a.bit_length()) #输出为3

      字符串:str

        (srt型所有功能都在 str 里面,在Pychram中建立文件输入str,按住Crtl鼠标点击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         """
     17         S.capitalize() -> str
     18 
     19         Return a capitalized version of S, i.e. make the first character
     20         have upper case and the rest lower case.
     21         """
     22         return ""
     23 
     24     def casefold(self): # real signature unknown; restored from __doc__
     25         """ 所有字符小写(比更加牛能把很多未知的对应变小写)"""
     26         """
     27         S.casefold() -> str
     28 
     29         Return a version of S suitable for caseless comparisons.
     30         """
     31         return ""
     32 
     33     def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
     34         """字符居中; width:总长度 ; fillchar:空白处填内容 默认无"""
     35         """
     36         S.center(width[, fillchar]) -> str
     37 
     38         Return S centered in a string of length width. Padding is
     39         done using the specified fill character (default is a space)
     40         """
     41         return ""
     42 
     43     def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
     44         """计算出字符串sub参数在出现几次, start:起始位置;end:结束位置"""
     45         """
     46         S.count(sub[, start[, end]]) -> int
     47 
     48         Return the number of non-overlapping occurrences of substring sub in
     49         string S[start:end].  Optional arguments start and end are
     50         interpreted as in slice notation.
     51         """
     52         return 0
     53 
     54     def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
     55         """判断是否以suffix参数结尾 start:起始位置;end结束位置"""
     56         """
     57         S.endswith(suffix[, start[, end]]) -> bool
     58 
     59         Return True if S ends with the specified suffix, False otherwise.
     60         With optional start, test S beginning at that position.
     61         With optional end, stop comparing S at that position.
     62         suffix can also be a tuple of strings to try.
     63         """
     64         return False
     65 
     66     def expandtabs(self, tabsize=8): # real signature unknown; restored from __doc__
     67         """以tabsize参数分割字符串,遇到'\t'不足的用空格补齐"""
     68         """
     69         S.expandtabs(tabsize=8) -> str
     70 
     71         Return a copy of S where all tab characters are expanded using spaces.
     72         If tabsize is not given, a tab size of 8 characters is assumed.
     73         """
     74         return ""
     75 
     76     def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
     77         """寻找子序列,找到第一个返回位置,找不到返回-1"""
     78         """
     79         S.find(sub[, start[, end]]) -> int
     80 
     81         Return the lowest index in S where substring sub is found,
     82         such that sub is contained within S[start:end].  Optional
     83         arguments start and end are interpreted as in slice notation.
     84 
     85         Return -1 on failure.
     86         """
     87         return 0
     88 
     89     def format(*args, **kwargs): # known special case of str.format
     90         """字符串插入,动态参数,第一个参数列表形式,第二个传入字典"""
     91         """
     92         S.format(*args, **kwargs) -> str
     93 
     94         Return a formatted version of S, using substitutions from args and kwargs.
     95         The substitutions are identified by braces ('{' and '}').
     96         """
     97         pass
     98 
     99     def format_map(self, mapping): # real signature unknown; restored from __doc__
    100         """传入格式为字典形式的"""
    101         """
    102         S.format_map(mapping) -> str
    103 
    104         Return a formatted version of S, using substitutions from mapping.
    105         The substitutions are identified by braces ('{' and '}').
    106         """
    107         return ""
    108 
    109     def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    110         """和find一样寻找子序列位置,但没找到会报错,"""
    111         """
    112         S.index(sub[, start[, end]]) -> int
    113 
    114         Like S.find() but raise ValueError when the substring is not found.
    115         """
    116         return 0
    117 
    118     def isalnum(self): # real signature unknown; restored from __doc__
    119         """判断是否只有数字和字符 是返回true,否则返回false"""
    120         """
    121         S.isalnum() -> bool
    122 
    123         Return True if all characters in S are alphanumeric
    124         and there is at least one character in S, False otherwise.
    125         """
    126         return False
    127 
    128     def isalpha(self): # real signature unknown; restored from __doc__
    129         """判断是否只有字符 是返回true,否则返回false"""
    130         """
    131         S.isalpha() -> bool
    132 
    133         Return True if all characters in S are alphabetic
    134         and there is at least one character in S, False otherwise.
    135         """
    136         return False
    137 
    138     def isdecimal(self): # real signature unknown; restored from __doc__
    139         """判断是否是数字(实际中用的更多) 是返回true,否则返回false"""
    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         """判断是否是数字(比上面支持的种类多,不支持中文如二) 是返回true,否则返回false"""
    150         """
    151         S.isdigit() -> bool
    152 
    153         Return True if all characters in S are digits
    154         and there is at least one character in S, False otherwise.
    155         """
    156         return False
    157 
    158     def isidentifier(self): # real signature unknown; restored from __doc__
    159         """是否符合变量的书写方式"""
    160         """
    161         S.isidentifier() -> bool
    162 
    163         Return True if S is a valid identifier according
    164         to the language definition.
    165 
    166         Use keyword.iskeyword() to test for reserved identifiers
    167         such as "def" and "class".
    168         """
    169         return False
    170 
    171     def islower(self): # real signature unknown; restored from __doc__
    172         """判断字母是否全是小写"""
    173         """
    174         S.islower() -> bool
    175 
    176         Return True if all cased characters in S are lowercase and there is
    177         at least one cased character in S, False otherwise.
    178         """
    179         return False
    180 
    181     def isnumeric(self): # real signature unknown; restored from __doc__
    182         """判断是否是数字(支持更多如中文) 是返回true,否则返回false"""
    183         """
    184         S.isnumeric() -> bool
    185 
    186         Return True if there are only numeric characters in S,
    187         False otherwise.
    188         """
    189         return False
    190 
    191     def isprintable(self): # real signature unknown; restored from __doc__
    192         """是否有不可显示的字符串如'\t','\n'"""
    193         """
    194         S.isprintable() -> bool
    195 
    196         Return True if all characters in S are considered
    197         printable in repr() or S is empty, False otherwise.
    198         """
    199         return False
    200 
    201     def isspace(self): # real signature unknown; restored from __doc__
    202         """是否全是空格"""
    203         """
    204         S.isspace() -> bool
    205 
    206         Return True if all characters in S are whitespace
    207         and there is at least one character in S, False otherwise.
    208         """
    209         return False
    210 
    211     def istitle(self): # real signature unknown; restored from __doc__
    212         """是否是标题形式的如 The Book (首字母大写)"""
    213         """
    214         S.istitle() -> bool
    215 
    216         Return True if S is a titlecased string and there is at least one
    217         character in S, i.e. upper- and titlecase characters may only
    218         follow uncased characters and lowercase characters only cased ones.
    219         Return False otherwise.
    220         """
    221         return False
    222 
    223     def isupper(self): # real signature unknown; restored from __doc__
    224         """判断字母是否全部是大写"""
    225         """
    226         S.isupper() -> bool
    227 
    228         Return True if all cased characters in S are uppercase and there is
    229         at least one cased character in S, False otherwise.
    230         """
    231         return False
    232 
    233     def join(self, iterable): # real signature unknown; restored from __doc__
    234         """将iterable参数中的每个元素按照指定分隔符(调用join的变量)进行拼接"""
    235         """
    236         S.join(iterable) -> str
    237 
    238         Return a string which is the concatenation of the strings in the
    239         iterable.  The separator between elements is S.
    240         """
    241         return ""
    242 
    243     def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
    244         """将字符串放在左边,用法和center一样"""
    245         """
    246         S.ljust(width[, fillchar]) -> str
    247 
    248         Return S left-justified in a Unicode string of length width. Padding is
    249         done using the specified fill character (default is a space).
    250         """
    251         return ""
    252 
    253     def lower(self): # real signature unknown; restored from __doc__
    254         """将字符串转换成小写"""
    255         """
    256         S.lower() -> str
    257 
    258         Return a copy of the string S converted to lowercase.
    259         """
    260         return ""
    261 
    262     def lstrip(self, chars=None): # real signature unknown; restored from __doc__
    263         """去除左边开始chars参数所代表的字符串(包括其子字符串可自由组合),没有不去除,不填默认去除多余空格还有('\t','\]n');"""
    264         """
    265         S.lstrip([chars]) -> str
    266 
    267         Return a copy of the string S with leading whitespace removed.
    268         If chars is given and not None, remove characters in chars instead.
    269         """
    270         return ""
    271 
    272     def maketrans(self, *args, **kwargs): # real signature unknown
    273         """做一个对应关系 如maketrans("abcd','1234') 将'abcvd','1234'一一对应返回,
    274         调用translate时用到 用后面的替换前面的"""
    275         """
    276         Return a translation table usable for str.translate().
    277 
    278         If there is only one argument, it must be a dictionary mapping Unicode
    279         ordinals (integers) or characters to Unicode ordinals, strings or None.
    280         Character keys will be then converted to ordinals.
    281         If there are two arguments, they must be strings of equal length, and
    282         in the resulting dictionary, each character in x will be mapped to the
    283         character at the same position in y. If there is a third argument, it
    284         must be a string, whose characters will be mapped to None in the result.
    285         """
    286         pass
    287 
    288     def partition(self, sep): # real signature unknown; restored from __doc__
    289         """从左边开始找到sep参数相同的字符串开始分割,('xx','sep','xx')"""
    290         """
    291         S.partition(sep) -> (head, sep, tail)
    292 
    293         Search for the separator sep in S, and return the part before it,
    294         the separator itself, and the part after it.  If the separator is not
    295         found, return S and two empty strings.
    296         """
    297         pass
    298 
    299     def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
    300         """用新的代替老的字符串"""
    301         """
    302         S.replace(old, new[, count]) -> str
    303 
    304         Return a copy of S with all occurrences of substring
    305         old replaced by new.  If the optional argument count is
    306         given, only the first count occurrences are replaced.
    307         """
    308         return ""
    309 
    310     def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    311         """和find一样,但是从右边开始寻找"""
    312         """
    313         S.rfind(sub[, start[, end]]) -> int
    314 
    315         Return the highest index in S where substring sub is found,
    316         such that sub is contained within S[start:end].  Optional
    317         arguments start and end are interpreted as in slice notation.
    318 
    319         Return -1 on failure.
    320         """
    321         return 0
    322 
    323     def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    324         """和index一样, 但是从右边开始寻找"""
    325         """
    326         S.rindex(sub[, start[, end]]) -> int
    327 
    328         Like S.rfind() but raise ValueError when the substring is not found.
    329         """
    330         return 0
    331 
    332     def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
    333         """将字符串放在右边,用法和center一样"""
    334         """
    335         S.rjust(width[, fillchar]) -> str
    336 
    337         Return S right-justified in a string of length width. Padding is
    338         done using the specified fill character (default is a space).
    339         """
    340         return ""
    341 
    342     def rpartition(self, sep): # real signature unknown; restored from __doc__
    343         """从右边开始找到sep参数相同的字符串开始分割,('xx','sep','xx')"""
    344         """
    345         S.rpartition(sep) -> (head, sep, tail)
    346 
    347         Search for the separator sep in S, starting at the end of S, and return
    348         the part before it, the separator itself, and the part after it.  If the
    349         separator is not found, return two empty strings and S.
    350         """
    351         pass
    352 
    353     def rsplit(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
    354         """从右边开始找到sep参数相同的字符串开始分割,分割时去掉sep;maxsplit:代表找几次;('xx','xx')"""
    355         """
    356         S.rsplit(sep=None, maxsplit=-1) -> list of strings
    357 
    358         Return a list of the words in S, using sep as the
    359         delimiter string, starting at the end of the string and
    360         working to the front.  If maxsplit is given, at most maxsplit
    361         splits are done. If sep is not specified, any whitespace string
    362         is a separator.
    363         """
    364         return []
    365 
    366     def rstrip(self, chars=None): # real signature unknown; restored from __doc__
    367         """去除右边开始chars参数所代表的字符串(包括其子字符串可自由组合),没有不去除(只有前一个去了后面才能去),
    368         不填默认去除多余空格还有('\t','\]n');"""
    369         """
    370         S.rstrip([chars]) -> str
    371 
    372         Return a copy of the string S with trailing whitespace removed.
    373         If chars is given and not None, remove characters in chars instead.
    374         """
    375         return ""
    376 
    377     def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
    378         """从左边开始找到sep参数相同的字符串开始分割,分割时去掉sep;maxsplit:代表找几次;('xx','xx')"""
    379         """
    380         S.split(sep=None, maxsplit=-1) -> list of strings
    381 
    382         Return a list of the words in S, using sep as the
    383         delimiter string.  If maxsplit is given, at most maxsplit
    384         splits are done. If sep is not specified or is None, any
    385         whitespace string is a separator and empty strings are
    386         removed from the result.
    387         """
    388         return []
    389 
    390     def splitlines(self, keepends=None): # real signature unknown; restored from __doc__
    391         """分割,按照'\n'分割,keepends:true保留换行符,false不保留换行符"""
    392         """
    393         S.splitlines([keepends]) -> list of strings
    394 
    395         Return a list of the lines in S, breaking at line boundaries.
    396         Line breaks are not included in the resulting list unless keepends
    397         is given and true.
    398         """
    399         return []
    400 
    401     def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
    402         """判断是否以prefix参数开头 start:起始位置;end结束位置"""
    403         """
    404         S.startswith(prefix[, start[, end]]) -> bool
    405 
    406         Return True if S starts with the specified prefix, False otherwise.
    407         With optional start, test S beginning at that position.
    408         With optional end, stop comparing S at that position.
    409         prefix can also be a tuple of strings to try.
    410         """
    411         return False
    412 
    413     def strip(self, chars=None): # real signature unknown; restored from __doc__
    414         """去除两边开始chars参数所代表的字符串(包括其子字符串可自由组合),没有不去除(只有前一个去了后面才能去),
    415         不填默认去除多余空格还有('\t','\]n');"""
    416         """
    417         S.strip([chars]) -> str
    418 
    419         Return a copy of the string S with leading and trailing
    420         whitespace removed.
    421         If chars is given and not None, remove characters in chars instead.
    422         """
    423         return ""
    424 
    425     def swapcase(self): # real signature unknown; restored from __doc__
    426         """大小写转换"""
    427         """
    428         S.swapcase() -> str
    429 
    430         Return a copy of S with uppercase characters converted to lowercase
    431         and vice versa.
    432         """
    433         return ""
    434 
    435     def title(self): # real signature unknown; restored from __doc__
    436         """将字符串转换成标题形式"""
    437         """
    438         S.title() -> str
    439 
    440         Return a titlecased version of S, i.e. words start with title case
    441         characters, all remaining cased characters have lower case.
    442         """
    443         return ""
    444 
    445     def translate(self, table): # real signature unknown; restored from __doc__
    446         """按照table参数表示的一一对应关系替换 变量中的值 ,返回替换后的字符串"""
    447         """
    448         S.translate(table) -> str
    449 
    450         Return a copy of the string S in which each character has been mapped
    451         through the given translation table. The table must implement
    452         lookup/indexing via __getitem__, for instance a dictionary or list,
    453         mapping Unicode ordinals to Unicode ordinals, strings, or None. If
    454         this operation raises LookupError, the character is left untouched.
    455         Characters mapped to None are deleted.
    456         """
    457         return ""
    458 
    459     def upper(self): # real signature unknown; restored from __doc__
    460         """将字符串中字母全部变成大写"""
    461         """
    462         S.upper() -> str
    463 
    464         Return a copy of S converted to uppercase.
    465         """
    466         return ""
    467 
    468     def zfill(self, width): # real signature unknown; restored from __doc__
    469         """将字符串放在右边和 width:代表宽度  ;默认用0填充"""
    470         """
    471         S.zfill(width) -> str
    472 
    473         Pad a numeric string S with zeros on the left, to fill a field
    474         of the specified width. The string S is never truncated.
    475         """
    476         return ""
    str

        1. 索引,切片:字符串可以用索引:a = "abc"    b = a[0]  切片:a = "abcdef"   b = a[0:2] (取第0 1 个,2为-1时就是到最后)

        2. len():a = len("中") 在Python3中输出a=1,字符串长度;  Python2中输出a=3 ,字节长度

        3. 还支持for循环如 :for b in a:

        4. 字符串一旦创建不可修改,修改和拼接都是产生的新的字符串

      列表:list

        (list型所有功能都在 int 里面,在Pychram中建立文件输入list,按住Crtl鼠标点击list 进入查看)

     1 class list(object):
     2     """
     3     list() -> new empty list
     4     list(iterable) -> new list initialized from iterable's items
     5     """
     6     def append(self, p_object): # real signature unknown; restored from __doc__
     7         """在元素当成整体后面追加字符串"""
     8         """ L.append(object) -> None -- append object to end """
     9         pass
    10 
    11     def clear(self): # real signature unknown; restored from __doc__
    12         """清空列表"""
    13         """ L.clear() -> None -- remove all items from L """
    14         pass
    15 
    16     def copy(self): # real signature unknown; restored from __doc__
    17         """拷贝  浅拷贝"""
    18         """ L.copy() -> list -- a shallow copy of L """
    19         return []
    20 
    21     def count(self, value): # real signature unknown; restored from __doc__
    22         """计算出元素出现的次数"""
    23         """ L.count(value) -> integer -- return number of occurrences of value """
    24         return 0
    25 
    26     def extend(self, iterable): # real signature unknown; restored from __doc__
    27         """将每个元素元素追加到后面 参数要是可迭代对象"""
    28         """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """
    29         pass
    30 
    31     def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
    32         """找元素的位置 左边优先"""
    33         """
    34         L.index(value, [start, [stop]]) -> integer -- return first index of value.
    35         Raises ValueError if the value is not present.
    36         """
    37         return 0
    38 
    39     def insert(self, index, p_object): # real signature unknown; restored from __doc__
    40         """插入元素;index:要插入值的位置;p_object要插入的值"""
    41         """ L.insert(index, object) -- insert object before index """
    42         pass
    43 
    44     def pop(self, index=None): # real signature unknown; restored from __doc__
    45         """删除某个值返回被删除的值;index:要删除的值的索引;默认情况下删除最后一个"""
    46         """
    47         L.pop([index]) -> item -- remove and return item at index (default last).
    48         Raises IndexError if list is empty or index is out of range.
    49         """
    50         pass
    51 
    52     def remove(self, value): # real signature unknown; restored from __doc__
    53         """删除;value:要删除的元素"""
    54         """
    55         L.remove(value) -> None -- remove first occurrence of value.
    56         Raises ValueError if the value is not present.
    57         """
    58         pass
    59 
    60     def reverse(self): # real signature unknown; restored from __doc__
    61         """当前列表进行反转"""
    62         """ L.reverse() -- reverse *IN PLACE* """
    63         pass
    64 
    65     def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__
    66         """帮忙排序;reverse=true 从大到小,reverse=false 从小到大"""
    67         """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
    68         pass
    list

        1. 中括号括起来,用 , 分割元素

        2. 列表中可以是数字,字符串,列表 , 布尔值 ,元组,字典

        3. 支持索引分割for,while,       可迭代

        4. 可以被修改 通过索引和切片,

        5. 可以通过索引和切片删除如 del(a[i])  

        6. 列表换成字符转,如果没有数字直接用字符串的join函数,有数字就只能通过for循环

      元组:tuple

        (tuple型所有功能都在 tuple 里面,在Pychram中建立文件输入list,按住Crtl鼠标点击tuple 进入查看)

        

     1 class tuple(object):
     2     """
     3     tuple() -> empty tuple
     4     tuple(iterable) -> tuple initialized from iterable's items
     5     
     6     If the argument is a tuple, the return value is the same object.
     7     """
     8     def count(self, value): # real signature unknown; restored from __doc__
     9         """计算出元素的个数"""
    10         """ T.count(value) -> integer -- return number of occurrences of value """
    11         return 0
    12 
    13     def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
    14         """索引出元素所在位置; value:索引的值;start:起始位置;stop:结束位置"""
    15         """
    16         T.index(value, [start, [stop]]) -> integer -- return first index of value.
    17         Raises ValueError if the value is not present.
    18         """
    19         return 0
    tuple

        1. 元组用()括起来 ,一般写元组的时候在后面加个 ,

        2. 元组的元素(一级元素)不可修改,不能被增加或者删除,但是如果元组里面的元素的元素如果是可修改类型就可以修改

        3. 一般写元素的时候推荐在最好加入

        4. 可以被索引,切片,for循环,是可迭代对象

      字典:dict

        (dict型所有功能都在 dict 里面,在Pychram中建立文件输入dict,按住Crtl鼠标点击dict 进入查看)

     1 class dict(object):
     2     """
     3     dict() -> new empty dictionary
     4     dict(mapping) -> new dictionary initialized from a mapping object's
     5         (key, value) pairs
     6     dict(iterable) -> new dictionary initialized as if via:
     7         d = {}
     8         for k, v in iterable:
     9             d[k] = v
    10     dict(**kwargs) -> new dictionary initialized with the name=value pairs
    11         in the keyword argument list.  For example:  dict(one=1, two=2)
    12     """
    13     def clear(self): # real signature unknown; restored from __doc__
    14         """清空字典中的元素"""
    15         """ D.clear() -> None.  Remove all items from D. """
    16         pass
    17 
    18     def copy(self): # real signature unknown; restored from __doc__
    19         """浅拷贝"""
    20         """ D.copy() -> a shallow copy of D """
    21         pass
    22 
    23     @staticmethod # known case 支持类名加方法 如  dict.fromkeys
    24     def fromkeys(*args, **kwargs): # real signature unknown
    25         """根据序列创建一个字典 args:中间的元素当成key ; kwargs:中的元素当成value"""
    26         """ Returns a new dict with keys from iterable and values equal to value. """
    27         pass
    28 
    29     def get(self, k, d=None): # real signature unknown; restored from __doc__
    30         """根据key取字典中的值;不存在时可以指定默认值(NOLL)"""
    31         """ D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None. """
    32         pass
    33 
    34     def items(self): # real signature unknown; restored from __doc__
    35         """获取键值对"""
    36         """ D.items() -> a set-like object providing a view on D's items """
    37         pass
    38 
    39     def keys(self): # real signature unknown; restored from __doc__
    40         """获取key值"""
    41         """ D.keys() -> a set-like object providing a view on D's keys """
    42         pass
    43 
    44     def pop(self, k, d=None): # real signature unknown; restored from __doc__
    45         """删除键值对;k:想要删除的键值对;返回为删除的值;d:如果不存在时返回值"""
    46         """
    47         D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
    48         If key is not found, d is returned if given, otherwise KeyError is raised
    49         """
    50         pass
    51 
    52     def popitem(self): # real signature unknown; restored from __doc__
    53         """随机删除键值对;返回删除的键值对"""
    54         """
    55         D.popitem() -> (k, v), remove and return some (key, value) pair as a
    56         2-tuple; but raise KeyError if D is empty.
    57         """
    58         pass
    59 
    60     def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
    61         """设置值;如果存在不设置获取当前key对应的值,如果不存在添加,获取当前设置的值"""
    62         """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """
    63         pass
    64 
    65     def update(self, E=None, **F): # known special case of dict.update
    66         """更新字典里面上值"""
    67         """
    68         D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
    69         If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]
    70         If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
    71         In either case, this is followed by: for k in F:  D[k] = F[k]
    72         """
    73         pass
    74 
    75     def values(self): # real signature unknown; restored from __doc__
    76         """获取字典中的元素"""
    77         """ D.values() -> an object providing a view on D's values """
    78         pass
    dict

       1. 字典的格式 key值不能是可变值  bool值不能和(0,1)一起出现

    dic = {
        2 : 1,
        "key" : "abc",
        True : (1,2,3),
        (1,2) : {
            1 : 1,
            "key" : "abc",
            True : (1,2,3),
    
        }
    }

        2. 字典是无序的,不能进行切片

        3. 字典里面可以嵌套任意元素类型

        4. 可以通过索引的方式找到里面的元素

        5. 支持删除和for循环

       布尔值:bool

        1. 只有0 ,1

        2. None,'',(),[],{},0 =====>代表False

        

  • 相关阅读:
    vue响应式原理的实现
    手写 Promise
    模拟ATM机功能(C语言)
    打印空心菱形
    假设一对耗子每个月都可以生一对小耗子。小耗子生长3个月后,从第4个月开始也就能够生小耗子。问:假设所有的耗子都不死的话,那么20个月后一共有多少只耗子?
    判断一年中的第几天
    依次将10个数输入,要求打印出其中最大的数
    九九乘法表
    判断是否为闰年
    从键盘上接收一个字母,判断是否是大写字母,如果是则转换成小写字母输出 ,否则直接输出。
  • 原文地址:https://www.cnblogs.com/kaixindexiaocao/p/9677987.html
Copyright © 2020-2023  润新知