zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    CSS进阶(八) float
    CSS进阶(七)vertical-align
    CSS进阶(六) line-height
    CSS进阶(五)border
    CSS进阶(四)margin
    CSS进阶(三)padding
    ORA-01555 snapshot too old
    Ubuntu14.04LTS安装引发的蛋疼
    rancher 2 安装 longhorn
    rancher2 挂载ceph-rbd
  • 原文地址:https://www.cnblogs.com/itech/p/1926303.html
Copyright © 2011-2022 走看看