[Python] builtin abs() 함수


[Python] builtin abs() 함수

abs(x) 함수는 입력 받은 값의 절대값을 return 해주는 함수이다. 정의 def abs(*args, **kwargs): # real signature unknown Return the absolute value of the argument. 실행결과 sample = [ 10, - 10, 10.5, - 10.5, 0, 0.0, ] for s in sample: print('{} => {}'.format(s, abs(s))) """ 10 => 10 -10 => 10 10.5 => 10.5 -10.5 => 10.5 0 => 0 0.0 => 0.0 """ 이런식으로도 사용이 가능하다. from operator import __abs__ __abs__(10) 구현단 PyObject * PyNumber_Ab..


원문링크 : [Python] builtin abs() 함수