python 易错总结

  •  list的遍历问题:
    只有用下标访问list才能修改list里面的值
  • # coding=gbk
    # 只有用下标访问list才能修改list里面的值
    list = [-1, 2, 5, -8]
    for i in list:
            i += 8
    print(list)
    for i in range(0, len(list)):
            list[i] += 8
    print(list)

     

    # 环境配置:Anaconda  https://blog.csdn.net/DQ_DM/article/details/47065323  
    # pycharm如何使用Anaconda中安装好的包 https://blog.csdn.net/h4329201/article/details/80326801
    # pycharm 不显示代码提示 https://blog.csdn.net/MAOZEXIJR/article/details/78873687
    # pycharm 主题
    # anaconda  在powershell中无法使用activate指令激活环境,需要进入到cmd中(至少我是这样)
    a = 'foo'
    b = 5
    c = a
    type(a) # str
    isinstance(a, (int, str))   # true
    isinstance(b, (int, str))   # true
    
    c is a # true, C和a指向同一个对象
    c is not a # false
    
    # 字符串、元组是常量,不可修改
    ['apple', 'mango', 'carrot', 'banana'] # 列表
    ('python', 'elephant', 'penguin') # 元组
    {
        'Swaroop': 'swaroop@swaroopch.com',
        'Larry': 'larry@wall.org',
        'Matsumoto': 'matz@ruby-lang.org',
        'Spammer': 'spammer@hotmail.com'
    } # 字典
    set2 = set([6, 7, 7, 8, 8, 9]) # 用set创建集合
    
    # 列表表达式,在一组字符串上执行同一条操作
    # 在一组字符串line上执行同一条操作json.loads
    records = [json.loads(line) for line in open(path) if line is not Null]

     

posted on 2018-04-21 19:31  jkn1234  阅读(268)  评论(0编辑  收藏  举报