• 这是表格


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

    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'))
  • 相关阅读:
    不相交集实现实例
    TQ2440开发板挂载U盘出现乱码
    快速选择实例
    linux2.6.30.4内核移植(7)——插入hello world驱动模块
    linux2.6.30.4内核移植(6)——移植应用程序hello world常见的错误:-bin/sh ./hello not found
    linux2.6.30.4内核移植(5)——构建根文件系统(yaffs文件系统格式的镜像)
    linux2.6.30.4内核移植(4)——完善串口驱动
    linux2.6.30.4内核移植(3)——yaffs文件系统移植
    linux2.6.30.4内核移植(2)——Nand Flash驱动移植
    快速排序实例
  • 原文地址:https://www.cnblogs.com/jimGraymane/p/11434882.html
Copyright © 2020-2023  润新知