• python基础31[list+tuple+set+dict+str+file的成员方法]


    列出常见类型的方法:


    def ListFunctions(lists):
      
    print ("------------------------------------------")
      
    print (type(lists))
      
    for item in dir(lists):
        
    if ( not item.startswith("__")):
          
    print (item)

    #list
    = [123#or list(1,2,3)
    ListFunctions(l)
    # tuple
    = (123)
    ListFunctions (t)
    #set
    = {123#or set(1,2,3)
    ListFunctions(s)
    #dict
    = {1:'1v'2:'2v'3:'3v'#or dict(1:'1v', 2:'2v', 3:'3v')
    ListFunctions(d)
    #str
    myStr="123" #or str("123")
    ListFunctions(myStr)

    #file
    file = open("test\\file.txt""r")
    ListFunctions(file)

    运行结果:

    ------------------------------------------
    <class 'list'>
    append
    count
    extend
    index
    insert
    pop
    remove
    reverse
    sort
    ------------------------------------------
    <class 'tuple'>
    count
    index
    ------------------------------------------
    <class 'set'>
    add
    clear
    copy
    difference
    difference_update
    discard
    intersection
    intersection_update
    isdisjoint
    issubset
    issuperset
    pop
    remove
    symmetric_difference
    symmetric_difference_update
    union
    update
    ------------------------------------------
    <class 'dict'>
    clear
    copy
    fromkeys
    get
    items
    keys
    pop
    popitem
    setdefault
    update
    values
    ------------------------------------------
    <class 'str'>
    _formatter_field_name_split
    _formatter_parser
    capitalize
    center
    count
    encode
    endswith
    expandtabs
    find
    format
    index
    isalnum
    isalpha
    isdecimal
    isdigit
    isidentifier
    islower
    isnumeric
    isprintable
    isspace
    istitle
    isupper
    join
    ljust
    lower
    lstrip
    maketrans
    partition
    replace
    rfind
    rindex
    rjust
    rpartition
    rsplit
    rstrip
    split
    splitlines
    startswith
    strip
    swapcase
    title
    translate
    upper
    zfill
    ------------------------------------------
    <class '_io.TextIOWrapper'>
    _CHUNK_SIZE
    _checkClosed
    _checkReadable
    _checkSeekable
    _checkWritable
    buffer
    close
    closed
    detach
    encoding
    errors
    fileno
    flush
    isatty
    line_buffering
    name
    newlines
    read
    readable
    readline
    readlines
    seek
    seekable
    tell
    truncate
    writable
    write
    writelines

    注意:

    open()函数返回的file object的类型取决与传入的mode。当open()使用(w,r,wt,rt)来打开文本文件时,它返回的是io.TextIOBase的子类型,特别地为io.TextIOWrapper。当使用buffering打开binary文件时,他返回的是io.BufferedIOBase的子类型,当为读时返回为io.BufferedReader,当为写或增加时返回为io.BufferedWriter,当为读写模式时,它返回的是io.BufferedRandom。当buffering没有指定时,返回的是io.rawiobase,io.fileio的子类型。

    完!


    作者:iTech
    微信公众号: cicdops
    出处:http://itech.cnblogs.com/
    github:https://github.com/cicdops/cicdops

  • 相关阅读:
    tcp/udp并发(大吞吐量)性能测试工具
    postman prerequest动态加密数据构造
    匹配ip的正则表达式
    通过adb命令保存并重命名截图
    python3 urlencode及urldecode
    Android安全测试工具Drozer coverity fortify
    windows下adb shell命令杀进程方式
    postman批量构造数据
    Android app发热功耗思路
    Jenkins+ant+Jenkins接口持续集成测试配置
  • 原文地址:https://www.cnblogs.com/itech/p/1926303.html
Copyright © 2020-2023  润新知