Python/Python

[Python 기초] 04. 함수(function), 내장 함수(built in function)

  • -
728x90

함수 또는 메소드라고 불리우는 것들

이미 우리는 초등학교때부터 함수라는 것을 배웠다.

내가 프로그래밍을 하면서 함수에대해서 가장 이해가 빠르게 됐었던 그림이다.

함수는 정말 매력적이다. 흔히들 function이 무슨 뜻이냐 했을때 함수면 이과 기능이면 문과

중, 고등학교때 함수면 함수고 기능이면 기능이지 왜 다른 뜻을 가졌냐라며 투덜댔었는데, 이제는 왜 이런 뜻들을 가지게 됐는지 확실히 알게 됐다.

프로그래밍에서 함수도 마찬가지다 어떤 매개변수가 들어가면 그 매개변수들로 특정 기능을 수행해서 그 결과를 반환하는 일을 하는 것

def add(x,y):return x+y
print(add(2,5))

def sub(x,y=3): return x-y  # 매개변수의 초기값을 설정할 수 있다.
print(sub(2))
print(sub(2,4))

def order(drink, many): # 이런식으로도 사용가능하다!
    return f"You ordered {many} cups of {drink}"

print(order("coffee", 3))

파이썬에 내장되어있는 함수들을 알아보자.

FunctionDescription

abs() Returns the absolute value of a number
all() Returns True if all items in an iterable object are true
any() Returns True if any item in an iterable object is true
ascii() Returns a readable version of an object. Replaces none-ascii characters with escape character
bin() Returns the binary version of a number
bool() Returns the boolean value of the specified object
bytearray() Returns an array of bytes
bytes() Returns a bytes object
callable() Returns True if the specified object is callable, otherwise False
chr() Returns a character from the specified Unicode code.
classmethod() Converts a method into a class method
compile() Returns the specified source as an object, ready to be executed
complex() Returns a complex number
delattr() Deletes the specified attribute (property or method) from the specified object
dict() Returns a dictionary (Array)
dir() Returns a list of the specified object's properties and methods
divmod() Returns the quotient and the remainder when argument1 is divided by argument2
enumerate() Takes a collection (e.g. a tuple) and returns it as an enumerate object
eval() Evaluates and executes an expression
exec() Executes the specified code (or object)
filter() Use a filter function to exclude items in an iterable object
float() Returns a floating point number
format() Formats a specified value
frozenset() Returns a frozenset object
getattr() Returns the value of the specified attribute (property or method)
globals() Returns the current global symbol table as a dictionary
hasattr() Returns True if the specified object has the specified attribute (property/method)
hash() Returns the hash value of a specified object
help() Executes the built-in help system
hex() Converts a number into a hexadecimal value
id() Returns the id of an object
input() Allowing user input
int() Returns an integer number
isinstance() Returns True if a specified object is an instance of a specified object
issubclass() Returns True if a specified class is a subclass of a specified object
iter() Returns an iterator object
len() Returns the length of an object
list() Returns a list
locals() Returns an updated dictionary of the current local symbol table
map() Returns the specified iterator with the specified function applied to each item
max() Returns the largest item in an iterable
memoryview() Returns a memory view object
min() Returns the smallest item in an iterable
next() Returns the next item in an iterable
object() Returns a new object
oct() Converts a number into an octal
open() Opens a file and returns a file object
ord() Convert an integer representing the Unicode of the specified character
pow() Returns the value of x to the power of y
print() Prints to the standard output device
property() Gets, sets, deletes a property
range() Returns a sequence of numbers, starting from 0 and increments by 1 (by default)
repr() Returns a readable version of an object
reversed() Returns a reversed iterator
round() Rounds a numbers
set() Returns a new set object
setattr() Sets an attribute (property/method) of an object
slice() Returns a slice object
sorted() Returns a sorted list
@staticmethod() Converts a method into a static method
str() Returns a string object
sum() Sums the items of an iterator
super() Returns an object that represents the parent class
tuple() Returns a tuple
type() Returns the type of an object
vars() Returns the __dict__ property of an object
zip() Returns an iterator, from two or more iterators

출처 : https://www.w3schools.com/python/python_ref_functions.asp

 

Python Built-in Functions

Python Built in Functions Python has a set of built-in functions. Function Description abs()Returns the absolute value of a number all()Returns True if all items in an iterable object are true any()Returns True if any item in an iterable object is true asc

www.w3schools.com

 

728x90
300x250
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.