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
l = [1, 2, 3] #or list(1,2,3)
ListFunctions(l)
# tuple
t = (1, 2, 3)
ListFunctions (t)
#set
s = {1, 2, 3} #or set(1,2,3)
ListFunctions(s)
#dict
d = {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)
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
<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的子類型。
完!


浙公網安備 33010602011771號