Python內建函式總結及詳解
………………吧啦吧啦………………
2個多月來,將3.5版本中的68個內建函式,按順序逐個進行了自認為詳細的解析。為了方便記憶,將這些內建函式進行了如下分類:
- 數學運算(7個)
- 型別轉換(24個)
- 序列操作(8個)
- 物件操作(7個)
- 反射操作(8個)
- 變數操作(2個)
- 互動操作(2個)
- 檔案操作(1個)
- 編譯執行(4個)
數學運算
abs:求數值的絕對值
>>> abs(-2)
2
divmod:返回兩個數值的商和餘數
>>> divmod(5,2)
(2, 1)
>> divmod(5.5,2)
(2.0, 1.5)
max:返回可迭代物件中的元素中的最大值或者所有引數的最大值
>>> max(1,2,3) # 傳入3個引數 取3箇中較大者
3
>>> max('1234') # 傳入1個可迭代物件,取其最大元素值
'4'
>>> max(-1,0) # 數值預設取數值較大者
0
>>> max(-1,0,key = abs) # 傳入了求絕對值函式,則引數都會進行求絕對值後再取較大者
-1
min:返回可迭代物件中的元素中的最小值或者所有引數的最小值
>>> min(1,2,3) # 傳入3個引數 取3箇中較小者
1
>>> min('1234') # 傳入1個可迭代物件,取其最小元素值
'1'
>>> min(-1,-2) # 數值預設取數值較小者
-2
>>> min(-1,-2,key = abs) # 傳入了求絕對值函式,則引數都會進行求絕對值後再取較小者
-1
pow:返回兩個數值的冪運算值或求冪後與另一數值的餘數
>>> pow(2,3) #等價於 2**3
>>> pow(2,3,5) #等價於 pow(2,3)%5
round:對浮點數進行四捨五入求值
>>> round(1.1314926,1)
1.1
>>> round(1.1314926 ,5)
1.13149
sum:對元素型別是數值的可迭代物件中的每個元素求和
# 傳入可迭代物件
>>> sum((1,2,3,4))
10
# 元素型別必須是數值型
>>> sum((1.5,2.5,3.5,4.5))
12.0
>>> sum((1,2,3,4),-10)
0
型別轉換
bool:根據傳入的引數的邏輯值建立一個新的布林值
>>> bool() #未傳入引數
False
>>> bool(0) #數值0、空序列等值為False
False
>>> bool(1)
True
int:根據傳入的引數建立一個新的整數
>>> int() #不傳入引數時,得到結果0。
0
>>> int(3)
3
>>> int(3.6)
3
float:根據傳入的引數建立一個新的浮點數
>>> float() #不提供引數的時候,返回0.0
0.0
>>> float(3)
3.0
>>> float('3')
3.0
complex:根據傳入引數建立一個新的複數
>>> complex() #當兩個引數都不提供時,返回複數 0j。
0j
>>> complex('1+2j') #傳入字串建立複數
(1+2j)
>>> complex(1,2) #傳入數值建立複數
(1+2j)
str:返回一個物件的字串表現形式(給使用者)
>>> str()
''
>>> str(None)
'None'
>>> str('abc')
'abc'
>>> str(123)
'123'
bytearray:根據傳入的引數建立一個新的位元組陣列
>>> bytearray('中文','utf-8')
bytearray(b'\xe4\xb8\xad\xe6\x96\x87')
bytes:根據傳入的引數建立一個新的不可變位元組陣列
>>> bytes('中文','utf-8')
b'\xe4\xb8\xad\xe6\x96\x87'
memoryview:根據傳入的引數建立一個新的記憶體檢視物件
>>> v = memoryview(b'abcefg')
>>> v[1]
98
>>> v[-1]
103
ord:返回Unicode字元對應的整數
>>> ord('a')
97
chr:返回整數所對應的Unicode字元
>>> chr(97) #引數型別為整數
'a'
bin:將整數轉換成2進位制字串
>>> bin(3)
'0b11'
oct:將整數轉化成8進位制數字符串
>>> oct(10)
'0o12'
hex:將整數轉換成16進位制字串
>>> hex(15)
'0xf'
tuple:根據傳入的引數建立一個新的元組
>>> tuple() #不傳入引數,建立空元組
()
>>> tuple('121') #傳入可迭代物件。使用其元素建立新的元組
('1', '2', '1')
list:根據傳入的引數建立一個新的列表
>>>list() # 不傳入引數,建立空列表
[]
>>> list('abcd') # 傳入可迭代物件,使用其元素建立新的列表
['a', 'b', 'c', 'd']
dict:根據傳入的引數建立一個新的字典
>>> dict() # 不傳入任何引數時,返回空字典。
{}
>>> dict(a = 1,b = 2) # 可以傳入鍵值對建立字典。
{'b': 2, 'a': 1}
>>> dict(zip(['a','b'],[1,2])) # 可以傳入對映函式建立字典。
{'b': 2, 'a': 1}
>>> dict((('a',1),('b',2))) # 可以傳入可迭代物件建立字典。
{'b': 2, 'a': 1}
set:根據傳入的引數建立一個新的集合
>>>set() # 不傳入引數,建立空集合
set()
>>> a = set(range(10)) # 傳入可迭代物件,建立集合
>>> a
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
frozenset:根據傳入的引數建立一個新的不可變集合
>>> a = frozenset(range(10))
>>> a
frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
enumerate:根據可迭代物件建立列舉物件
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1)) #指定起始值
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
range:根據傳入的引數建立一個新的range物件
>>> a = range(10)
>>> b = range(1,10)
>>> c = range(1,10,3)
>>> a,b,c # 分別輸出a,b,c
(range(0, 10), range(1, 10), range(1, 10, 3))
>>> list(a),list(b),list(c) # 分別輸出a,b,c的元素
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 4, 7])
iter:根據傳入的引數建立一個新的可迭代物件
>>> a = iter('abcd') #字串序列
>>> a
<str_iterator object at 0x03FB4FB0>
>>> next(a)
'a'
>>> next(a)
'b'
>>> next(a)
'c'
>>> next(a)
'd'
>>> next(a)
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
next(a)
StopIteration
slice:根據傳入的引數建立一個新的切片物件
>>> c1 = slice(5) # 定義c1
>>> c1
slice(None, 5, None)
>>> c2 = slice(2,5) # 定義c2
>>> c2
slice(2, 5, None)
>>> c3 = slice(1,10,3) # 定義c3
>>> c3
slice(1, 10, 3)
super:根據傳入的引數建立一個新的子類和父類關係的代理物件
#定義父類A
>>> class A(object):
def __init__(self):
print('A.__init__')
#定義子類B,繼承A
>>> class B(A):
def __init__(self):
print('B.__init__')
super().__init__()
#super呼叫父類方法
>>> b = B()
B.__init__
A.__init__
object:建立一個新的object物件
>>> a = object()
>>> a.name = 'kim' # 不能設定屬性
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
a.name = 'kim'
AttributeError: 'object' object has no attribute 'name'
序列操作
all:判斷可迭代物件的每個元素是否都為True值
>>> all([1,2]) #列表中每個元素邏輯值均為True,返回True
True
>>> all([0,1,2]) #列表中0的邏輯值為False,返回False
False
>>> all(()) #空元組
True
>>> all({}) #空字典
True
any:判斷可迭代物件的元素是否有為True值的元素
>>> any([0,1,2]) #列表元素有一個為True,則返回True
True
>>> any([0,0]) #列表元素全部為False,則返回False
False
>>> any([]) #空列表
False
>>> any({}) #空字典
False
filter:使用指定方法過濾可迭代物件的元素
>>> a = list(range(1,10)) #定義序列
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> def if_odd(x): #定義奇數判斷函式
return x%2==1
>>> list(filter(if_odd,a)) #篩選序列中的奇數
[1, 3, 5, 7, 9]
map:使用指定方法去作用傳入的每個可迭代物件的元素,生成新的可迭代物件
>>> a = map(ord,'abcd')
>>> a
<map object at 0x03994E50>
>>> list(a)
[97, 98, 99, 100]
next:返回可迭代物件中的下一個元素值
>>> a = iter('abcd')
>>> next(a)
'a'
>>> next(a)
'b'
>>> next(a)
'c'
>>> next(a)
'd'
>>> next(a)
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
next(a)
StopIteration
#傳入default引數後,如果可迭代物件還有元素沒有返回,則依次返回其元素值,如果所有元素已經返回,則返回default指定的預設值而不丟擲StopIteration 異常
>>> next(a,'e')
'e'
>>> next(a,'e')
'e'
reversed:反轉序列生成新的可迭代物件
>>> a = reversed(range(10)) # 傳入range物件
>>> a # 型別變成迭代器
<range_iterator object at 0x035634E8>
>>> list(a)
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
sorted:對可迭代物件進行排序,返回一個新的列表
>>> a = ['a','b','d','c','B','A']
>>> a
['a', 'b', 'd', 'c', 'B', 'A']
>>> sorted(a) # 預設按字元ascii碼排序
['A', 'B', 'a', 'b', 'c', 'd']
>>> sorted(a,key = str.lower) # 轉換成小寫後再排序,'a'和'A'值一樣,'b'和'B'值一樣
['a', 'A', 'b', 'B', 'c', 'd']
zip:聚合傳入的每個迭代器中相同位置的元素,返回一個新的元組型別迭代器
>>> x = [1,2,3] #長度3
>>> y = [4,5,6,7,8] #長度5
>>> list(zip(x,y)) # 取最小長度3
[(1, 4), (2, 5), (3, 6)]
物件操作
help:返回物件的幫助資訊
>>> help(str)
Help on class str in module builtins:
class str(object)
| str(object='') -> str
| str(bytes_or_buffer[, encoding[, errors]]) -> str
|
| Create a new string object from the given object. If encoding or
| errors is specified, then the object must expose a data buffer
| that will be decoded using the given encoding and error handler.
| Otherwise, returns the result of object.__str__() (if defined)
| or repr(object).
| encoding defaults to sys.getdefaultencoding().
| errors defaults to 'strict'.
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __eq__(self, value, /)
| Return self==value.
|
| __format__(...)
| S.__format__(format_spec) -> str
|
| Return a formatted version of S as described by format_spec.
-- More --
dir:返回物件或者當前作用域內的屬性列表
>>> import math
>>> math
<module 'math' (built-in)>
>>> dir(math)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
id:返回物件的唯一識別符號
>>> a = 'some text'
>>> id(a)
69228568
hash:獲取物件的雜湊值
>>> hash('good good study')
1032709256
type:返回物件的型別,或者根據傳入的引數建立一個新的型別
>>> type(1) # 返回物件的型別
<class 'int'>
#使用type函式建立型別D,含有屬性InfoD
>>> D = type('D',(A,B),dict(InfoD='some thing defined in D'))
>>> d = D()
>>> d.InfoD
'some thing defined in D'
len:返回物件的長度
>>> len('abcd') # 字串
>>> len(bytes('abcd','utf-8')) # 位元組陣列
>>> len((1,2,3,4)) # 元組
>>> len([1,2,3,4]) # 列表
>>> len(range(1,5)) # range物件
>>> len({'a':1,'b':2,'c':3,'d':4}) # 字典
>>> len({'a','b','c','d'}) # 集合
>>> len(frozenset('abcd')) #不可變集合
ascii:返回物件的可打印表字串表現方式
>>> ascii(1)
'1'
>>> ascii('&')
"'&'"
>>> ascii(9000000)
'9000000'
>>> ascii('中文') #非ascii字元
"'\\u4e2d\\u6587'"
format:格式化顯示值
#字串可以提供的引數 's' None
>>> format('some string','s')
'some string'
>>> format('some string')
'some string'
#整形數值可以提供的引數有 'b' 'c' 'd' 'o' 'x' 'X' 'n' None
>>> format(3,'b') #轉換成二進位制
'11'
>>> format(97,'c') #轉換unicode成字元
'a'
>>> format(11,'d') #轉換成10進位制
'11'
>>> format(11,'o') #轉換成8進位制
'13'
>>> format(11,'x') #轉換成16進位制 小寫字母表示
'b'
>>> format(11,'X') #轉換成16進位制 大寫字母表示
'B'
>>> format(11,'n') #和d一樣
'11'
>>> format(11) #預設和d一樣
'11'
#浮點數可以提供的引數有 'e' 'E' 'f' 'F' 'g' 'G' 'n' '%' None
>>> format(314159267,'e') #科學計數法,預設保留6位小數
'3.141593e+08'
>>> format(314159267,'0.2e') #科學計數法,指定保留2位小數
'3.14e+08'
>>> format(314159267,'0.2E') #科學計數法,指定保留2位小數,採用大寫E表示
'3.14E+08'
>>> format(314159267,'f') #小數點計數法,預設保留6位小數
'314159267.000000'
>>> format(3.14159267000,'f') #小數點計數法,預設保留6位小數
'3.141593'
>>> format(3.14159267000,'0.8f') #小數點計數法,指定保留8位小數
'3.14159267'
>>> format(3.14159267000,'0.10f') #小數點計數法,指定保留10位小數
'3.1415926700'
>>> format(3.14e+1000000,'F') #小數點計數法,無窮大轉換成大小字母
'INF'
#g的格式化比較特殊,假設p為格式中指定的保留小數位數,先嚐試採用科學計數法格式化,得到冪指數exp,如果-4<=exp<p,則採用小數計數法,並保留p-1-exp位小數,否則按小數計數法計數,並按p-1保留小數位數
>>> format(0.00003141566,'.1g') #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留0位小數點
'3e-05'
>>> format(0.00003141566,'.2g') #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留1位小數點
'3.1e-05'
>>> format(0.00003141566,'.3g') #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留2位小數點
'3.14e-05'
>>> format(0.00003141566,'.3G') #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留0位小數點,E使用大寫
'3.14E-05'
>>> format(3.1415926777,'.1g') #p=1,exp=0 ==》 -4<=exp<p成立,按小數計數法計數,保留0位小數點
'3'
>>> format(3.1415926777,'.2g') #p=1,exp=0 ==》 -4<=exp<p成立,按小數計數法計數,保留1位小數點
'3.1'
>>> format(3.1415926777,'.3g') #p=1,exp=0 ==》 -4<=exp<p成立,按小數計數法計數,保留2位小數點
'3.14'
>>> format(0.00003141566,'.1n') #和g相同
'3e-05'
>>> format(0.00003141566,'.3n') #和g相同
'3.14e-05'
>>> format(0.00003141566) #和g相同
'3.141566e-05'
vars:返回當前作用域內的區域性變數和其值組成的字典,或者返回物件的屬性列表
#作用於類例項
>>> class A(object):
pass
>>> a.__dict__
{}
>>> vars(a)
{}
>>> a.name = 'Kim'
>>> a.__dict__
{'name': 'Kim'}
>>> vars(a)
{'name': 'Kim'}
反射操作
_import_:動態匯入模組
index = __import__('index')
index.sayHello()
isinstance:判斷物件是否是類或者型別元組中任意類元素的例項
>>> isinstance(1,int)
True
>>> isinstance(1,str)
False
>>> isinstance(1,(int,str))
True
issubclass:判斷類是否是另外一個類或者型別元組中任意類元素的子類
>>> issubclass(bool,int)
True
>>> issubclass(bool,str)
False
>>> issubclass(bool,(str,int))
True
hasattr:檢查物件是否含有屬性
#定義類A
>>> class Student:
def __init__(self,name):
self.name = name
>>> s = Student('Aim')
>>> hasattr(s,'name') #a含有name屬性
True
>>> hasattr(s,'age') #a不含有age屬性
False
getattr:獲取物件的屬性值
#定義類Student
>>> class Student:
def __init__(self,name):
self.name = name
>>> getattr(s,'name') #存在屬性name
'Aim'
>>> getattr(s,'age',6) #不存在屬性age,但提供了預設值,返回預設值
>>> getattr(s,'age') #不存在屬性age,未提供預設值,呼叫報錯
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
getattr(s,'age')
AttributeError: 'Stduent' object has no attribute 'age'
setattr:設定物件的屬性值
>>> class Student:
def __init__(self,name):
self.name = name
>>> a = Student('Kim')
>>> a.name
'Kim'
>>> setattr(a,'name','Bob')
>>> a.name
'Bob'
delattr:刪除物件的屬性
#定義類A
>>> class A:
def __init__(self,name):
self.name = name
def sayHello(self):
print('hello',self.name)
#測試屬性和方法
>>> a.name
'小麥'
>>> a.sayHello()
hello 小麥
#刪除屬性
>>> delattr(a,'name')
>>> a.name
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
a.name
AttributeError: 'A' object has no attribute 'name'
callable:檢測物件是否可被呼叫
>>> class B: #定義類B
def __call__(self):
print('instances are callable now.')
>>> callable(B) #類B是可呼叫物件
True
>>> b = B() #呼叫類B
>>> callable(b) #例項b是可呼叫物件
True
>>> b() #呼叫例項b成功
instances are callable now.
變數操作
globals:返回當前作用域內的全域性變數和其值組成的字典
>>> globals()
{'__spec__': None, '__package__': None, '__builtins__': <module 'builtins' (built-in)>, '__name__': '__main__', '__doc__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>}
>>> a = 1
>>> globals() #多了一個a
{'__spec__': None, '__package__': None, '__builtins__': <module 'builtins' (built-in)>, 'a': 1, '__name__': '__main__', '__doc__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>}
locals:返回當前作用域內的區域性變數和其值組成的字典
>>> def f():
print('before define a ')
print(locals()) #作用域內無變數
a = 1
print('after define a')
print(locals()) #作用域內有一個a變數,值為1
>>> f
<function f at 0x03D40588>
>>> f()
before define a
{}
after define a
{'a': 1}
互動操作
print:向標準輸出物件列印輸出
>>> print(1,2,3)
1 2 3
>>> print(1,2,3,sep = '+')
1+2+3
>>> print(1,2,3,sep = '+',end = '=?')
1+2+3=?
input:讀取使用者輸入值
>>> s = input('please input your name:')
please input your name:Ain
>>> s
'Ain'
檔案操作
open:使用指定的模式和編碼開啟檔案,返回檔案讀寫物件
# t為文字讀寫,b為二進位制讀寫
>>> a = open('test.txt','rt')
>>> a.read()
'some text'
>>> a.close()
編譯執行
compile:將字串編譯為程式碼或者AST物件,使之能夠通過exec語句來執行或者eval進行求值
>>> #流程語句使用exec
>>> code1 = 'for i in range(0,10): print (i)'
>>> compile1 = compile(code1,'','exec')
>>> exec (compile1)
0
1
2
相關推薦
Python內建函式總結及詳解
………………吧啦吧啦………………
2個多月來,將3.5版本中的68個內建函式,按順序逐個進行了自認為詳細的解析。為了方便記憶,將這些內建函式進行了如下分類:
數學運算(7個)
型別轉換(24個)
序列操作(8個)
物件操作(7個)
反射操作(8個)
變數操
Python內建函式詳解——總結篇
#字串可以提供的引數 's' None
>>> format('some string','s')
'some string'
>>> format('some string')
'some string'
#整形數值可以提供的引數有 'b' 'c' 'd' 'o'
python內建函式 sorted詳解
sorted作為python的內建全域性方法,用於可迭代序列的排序。
sorted函式接受3個引數:
sorted(iterable,key,reverse)sorted函式有以下特點:1)對列表排序,返回的物件不會改變原列表
>>> list =[1,2,3,
(轉)Python內建函式進階之“屬性(property())”詳解
原文:https://blog.csdn.net/GeekLeee/article/details/78519767
版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/GeekLeee/article/details/78519767屬性函式(property
Python內建函式(BIF)查詢(附中文詳解說明)
我們知道,Python 直譯器內建了一些常量和函式,叫做內建常量(Built-in Constants)和內建函式(Built-in Functions),來實現各種不同的特定功能,在我的另外一篇部落格中 第8章:Python計算生態 講述了一些常用的內建函式的使用方法,但是隨著Py
Python內建函式詳解【翻譯自python3.6官方文件共68個】
翻譯源 來自:https://docs.python.org/3/library/functions.html
abs(x)
返回一個數的絕對值。引數可以是一個整數或一個浮點數。若引數是複數,返回複數的模
all(iterable)
若 可迭代物件中所有元素為真
Python內建函式詳解
置頂 內建函式詳解 https://docs.python.org/3/library/functions.html?highlight=built#ascii
此文參考了別人整理好的東西(地址:http://www.cnblogs.co
Python內建函式open()詳解&檔案屬性方法詳解
Python檔案物件開啟模式及其屬性方法詳解1、檔案系統和檔案檔案系統:檔案系統是OS用於明確磁碟或分割槽上的檔案的方法和資料結構,即在磁碟上組織檔案的方法檔案:儲存在某種長期儲存裝置或臨時儲存裝置中的一段資料流,並且受計算機檔案系統管理。概括來講,檔案是計算機中有OS管理的
Python 內建函式sorted詳解和itemgetter, attrgetter
Python lists have a built-in
sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list
大佬用心良苦的學習乾貨,Python中的68個內建函式總結!
一、內建函式
10大類
數學運算(7個)
型別轉換(24個)
序列操作(8個)
物件操作(9個)
反射操作(8個)
變數操作(2個)
互動操作(2個)
檔案操作(1個)
編譯執行(4個)
python字串內建函式總結
字串內建總結
需要注意的是:
字串的單引號和雙引號都無法取消特殊字元的含義,如果想讓引號內所有字元均取消特殊意義,在引號前面加r,如name=r’l\thf’
unicode字串與r連用必需在r前面,如name=ur’l\thf’
大小寫處理
python內建函式及匿名函式
locals 本地作用域/區域性作用域 會隨著位置的改變而改變globals 全域性作用域 永遠不變 永遠是全域性
a = 1
b = 2
print(locals())
python中的內建函式總結
python提供了較多的內建函式,但感覺用得到的並不是很多,以下對函式做了一些歸納,list 、tuple、dict這三個因為經常用,就沒有寫上去
#python 內建函式,可直接呼叫
#為空的有: "" , () , {} , [] , None
boo
python編碼獲取排列組合的全部情況數及Python內建函式獲取排列組合
def permutations(iterable, r=None):
# permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3))
Python內建函式map
簡介
map()是 Python 內建的高階函式,它接收一個函式 func 和一個 list,並通過把函式 func依次作用在 list 的每個元素上,得到一個新的 list 並返回。
一、當list只有一個時
當list只有一個時,將函式func作用於這個list的每個元素上
【轉】Python 內建函式 locals() 和globals()
Python 內建函式 locals() 和globals()
轉自: https://blog.csdn.net/sxingming/article/details/52061630
python ----內建函式
def abs(*args, **kwargs)返回引數的絕對值。
a = -5
print(abs(a)) #列印結果:5
all(*args, **kwargs)all() 函式用於判斷給定的可迭代引數 iterable 中的所有元素是否都為
Python 內建函式 lambda、filter、map、reduce
轉載自:http://www.cnblogs.com/feeland/
Python 內建了一些比較特殊且實用的函式,使用這些能使你的程式碼簡潔而易讀。
下面對 Python 的 lambda、filter、map、reduce 進行初步的學習。red
Python 中 apply 內建函式(關鍵詞:Python/內建函式/apply)
>>> apply
<built-in function apply>
>>> def a():
... print 'i am a'
...
>>> apply(a)
i am a
>>> de
Python之路Python內建函式、zip()、max()、min() Python之路Python內建函式、zip()、max()、min()
Python之路Python內建函式、zip()、max()、min()
一、python內建函式
abs()
求絕對值
例子
print(abs(-2))
all()
把序列中每一個元素做布林運算,如果全部都是true,就返回true,