• 格式化字符串--原始字符串--列表--字典---的一些操作


    1 >>> s='hello'
    2 >>> s='so %s a day'
    3 >>> print s % 'beautiful'    格式化字符串  %s来作为一个变量站位
    4 so beautiful a day
    1 >>> import string
    2 >>> string.atoi('10')+1   数字转换为字符串
    3 11
    4 >>> str(10)+'1'
    5 '101'
    1 >>> import os
    2 >>> os.listdir(r'c:EFI')
    3 ['abc', 'Boot', 'Microsoft']    r''表示原始字符串 不在表示转义
    >>> list=['a','b','c',1,2]   列表的一些操作
    >>> list.append('A')
    >>> list
    ['a', 'b', 'c', 1, 2, 'A']
    >>> list.count('a')
    1
    >>> list.extend(list)
    >>> list
    ['a', 'b', 'c', 1, 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
    >>> list.index(1)
    3
    >>> list.insert(4,'B')
    >>> list
    ['a', 'b', 'c', 1, 'B', 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
    >>> list.pop(2)
    'c'
    >>> list
    ['a', 'b', 1, 'B', 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
    >>> list.remove('a')
    >>> list
    ['b', 1, 'B', 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
    >>> list.reverse()
    >>> list
    ['A', 2, 1, 'c', 'b', 'a', 'A', 2, 'B', 1, 'b']
    >>> list.sort()
    >>> list
    [1, 1, 2, 2, 'A', 'A', 'B', 'a', 'b', 'b', 'c']
     1 >>> dic={'apple':'red','pen':'balck'}   字典的一些操作
     2 >>> dic
     3 {'pen': 'balck', 'apple': 'red'}
     4 >>> dic.copy
     5 <built-in method copy of dict object at 0x0000000002C77488>
     6 >>> dic.copy()
     7 {'pen': 'balck', 'apple': 'red'}
     8 >>> dic.get('apple')
     9 'red'
    10 >>> dic.has_key('banna')
    11 False
    12 >>> dic.items()
    13 [('pen', 'balck'), ('apple', 'red')]
    14 >>> dic.keys()
    15 ['pen', 'apple']
    16 >>> dic.pop('apple')
    17 'red'
    18 >>> dic
    19 {'pen': 'balck'}
    20 >>> dic.update({'apple':'red'})
    21 >>> dic
    22 {'pen': 'balck', 'apple': 'red'}
    23 >>> dic.update({'apple':1})
    24 >>> dic
    25 {'pen': 'balck', 'apple': 1}
    26 >>> dic.values()
    27 ['balck', 1]
  • 相关阅读:
    k8s--容器挂载 error: /proc must be mounted
    mysql--read only
    C#读取Excel文件(.xls .xlsx)
    如何使用BBCode
    markdown使用经验积累
    openlayers学习之-----入门篇
    echarts学习之----动态排序柱状图
    echarts学习之----多图例折线图
    Web3D学习之-----全景图预览插件photo-sphere-viewer
    vue报错解决----npm ERR!
  • 原文地址:https://www.cnblogs.com/caojunjie/p/6742728.html
Copyright © 2020-2023  润新知