티스토리 뷰
함수의 정의
def 함수명(파라미터):
정의
return //생략 가능
내장함수
문자 변환 함수
str(int) // 소수점 생략
repr(int) //수수점 생략x
숫자 변환 함수
int(str)
list 관련 함수
len() // list의 길이 반환
remove(list) // list에서 특정 값 삭제
append(*) // 추가
sort() // 정렬
prime[*] // *번째 원소 삭제
=> prime[*] = 값 //*번째 원소를 값으로 변경
범위 배열 생성
range(2,7) // python2
list(range(2,7)) // python 3
=> [2,3,4,5,6]
list(range(5))
=> [0,1,2,3,4]
함수의 정의
def 함수명(파라미터):
정의
return //생략 가능
람다 lambda
lambda 인자 : 표현식
ex>
>>> def hap(x, y):
... return x + y ...
>>> hap(10, 20)
30
=> 람다로 표현
>>> (lambda x , y : x + y)(10, 20)
30
응용
map(함수, 리스트)
>>> map(lambda x: x ** 2, range(5)) # 파이썬 2
[0, 1, 4, 9, 16]
>>> list(map(lambda x: x ** 2, range(5))) # 파이썬 2 및 파이썬 3
[0, 1, 4, 9, 16]
reduce(함수, 순서형 자료)
>>> from functools import reduce # 파이썬 3에서는 써주셔야 해요
>>> reduce(lambda x, y: x + y, [0, 1, 2, 3, 4])
10
filter(함수, 리스트)
>>> filter(lambda x: x < 5, range(10)) # 파이썬 2
[0, 1, 2, 3, 4]
>>> list(filter(lambda x: x < 5, range(10))) # 파이썬 2 및 파이썬 3
[0, 1, 2, 3, 4]
>>> filter(lambda x: x % 2, range(10)) # 파이썬 2
[1, 3, 5, 7, 9]
>>> list(filter(lambda x: x % 2, range(10))) # 파이썬 2 및 파이썬 3
[1, 3, 5, 7, 9]
- Total
- Today
- Yesterday
- JavaScript
- facebook login
- JPA
- 페이스북 로그인
- jQuery
- Angular
- data grid component
- MySQL
- python3
- React-router
- Python
- data component module
- JSON
- angular router
- mobx
- https://www.tistory.com/auth/logout/
- Java
- data component
- localStorage
- 파이썬3
- data table component
- react
- Router
- CSS
- Spring Boot
- 파이썬
- Redux
- Spring
- data gird component
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |