• 这是表格


    列表内置方法:只能给列表用

    lt = [1, 2, 3]
    
    方法 代码
    索引取值/索引修改值 lt[0] = 2 print(lt)
    索引切片 print(lt[0:1])
    成员运算in/not in print(2 in lt) print(2 not in lt)
    for循环 for i in lt:print(i)
    len长度 print(len(lt))
    append():追加值 lt.append(4) print(lt)
    sort():排序 lt.sort() print(lt)
    reverse():反转 lt = [1, 2, 3]lt.reverse()print(lt)
    index():获取元素索引 print(lt.index(2))
    clear():清空列表 lt.clear() print(lt)
    copy():复制 lt = [1, 2, 3] lt1 = lt.copy() print(lt1)
    extend():扩展列表 lt1 = [1, 2, 3] lt2 = [1, 5, 6] lt1.extend(lt2) print(lt1)
    remove(): 移除 lt = [1, 2, 3] lt.remove(3) print(lt)
    insert():按照索引插入值 lt = [1, 2, 3] lt.insert(0, 1.5) print(lt)

    字典内置方法

    banzhuren_info_dic = {'name': 'guolaoshi', 'height': 150, 'weight': 130,                      'hobby_list': ['singing', 'dance', 'music']}
    
    方法 代码
    按key取值 print(banzhuren_info_dic['height'])
    按key修改值 banzhuren_info_dic['height'] = banzhuren_info_dic['height'] + 1 print(banzhuren_info_dic['height'])banzhuren_info_dic['age'] = 30
    按key增加值 anzhuren_info_dic['age'] = 30 print(banzhuren_info_dic)
    成员运算(比较的是key) print('age' in banzhuren_info_dic)
    for循环(对key循环) for i in banzhuren_info_dic: print(i)
    keys() print(banzhuren_info_dic.keys())
    values() print(banzhuren_info_dic.values())
    items() print(banzhuren_info_dic.items())
    get(): 取值 print(banzhuren_info_dic.get('height', 150))
    update() dic1 = {'a':1} dic2 = {'b':2} dic1.update(dic2) print(dic1)
    setdefault(): dic1 = {'a': 1} dic1.setdefault('a', 2) print(dic1)
    s='nick ugly'
    
    方法 代码
    索引取值 print(s[0])
    切片 print(s[0:4])
    成员运算 print('nick' in s) print('nick1' in s)
    for循环 for i in s: print(i)
    len() print(len(s))
    strip() print(s.strip('n* '))
    lstrip()/rstrip() 同上
    find()/index() s = 'nick'print(s.find('a'))
    join() print('*'.join(['a', 'b', 'c']))
    split() s = 'abc' print(s.split('*'))
    center/ljust/rjust print(s.center(50, '-'))
    isdigit()/isalpha() s = 'a'print(s.isdigit()) print(s.isalpha())#判断是否纯
    count() s = 'nick nick' print(s.count('nick'))
  • 相关阅读:
    应用程序如何实现高级量规界面自定义?这个第三方控件很好用
    Web应用开发的透视网格如何实现本地化?一招教你轻松搞定
    这个布局助手工具,帮你快速构建美观的WinForm应用
    用于Delphi的DevExpress VCL组件——增强布局控件性能
    JS/TS生成随机姓名
    单例模式的错误用法
    Node极速开发WebSocket服务器
    Unity中实现WebSocket客户端
    解决git每次输入密码的问题
    html转md
  • 原文地址:https://www.cnblogs.com/jimGraymane/p/11434882.html
Copyright © 2020-2023  润新知