일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 주피터노트북판다스
- SQL
- Python
- python데이터분석
- 파이썬시각화
- 판다스데이터분석
- python알고리즘
- 주피터노트북맷플롯립
- 주피터노트북데이터분석
- 팀플기록
- 파이썬알고리즘
- 수업기록
- 파이썬수업
- 판다스그래프
- 파이썬크롤링
- sql따라하기
- matplotlib
- 파이썬데이터분석
- 파이썬차트
- 파이썬데이터분석주피터노트북
- SQLSCOTT
- 파이썬
- sql연습
- SQL수업
- sql연습하기
- python수업
- 주피터노트북
- 데이터분석시각화
- 맷플롯립
- 주피터노트북그래프
- Today
- Total
목록python함수 (5)
IT_developers

화면 출력 print, 입력 input open("파일명", 모드, encoding...) : 파일을 읽거나 쓸 때 사용 with + open() : close()를 알아서 해줌 f = open("data/test1.txt", "w", encoding="utf-8") f.write("안녕하세요\n반갑습니다.") f.close() with open("data/test1.txt", "w", encoding="utf-8") as f: f.write("안녕하세요\n반갑습니다.") # 1~10까지 파일로 작성 # w : 기존에 있던 내용은 무시하고 새로 작성 f = open("data/test1.txt", "w", encoding="utf-8") for i in range(1, 11): f.write("%d\n"..

람다(Lambda) 함수 단일문으로 표현 되는 익명함수 코드 상에서 한 번만 사용되는 기능이 있을 때 굳이 함수로 만들지 않고 1회성으로 만들어서 사용 def square(x): return x**2 print(square(5)) # 람다식 변형 square = lambda x: x**2 print(type(square)) print(square(5)) def add(x, y): return x + y print(add(15, 2)) # 람다식 변형 add = lambda x, y: x + y print(add(15, 2)) 리스트 구조 # 문자의 길이가 짧은 순서대로 정렬하고 싶음 def str_len(s): return len(s) strings = ["bob", "charles", "alexande..

function 반복적으로 수행되는 부분을 함수록 작성 단독 실행 가능 타입을 쓰지 않음 변수명만 잘 써주면 됨 def 함수명 () : 수행할 문장1 수행할 문장2 # 함수 작성 def hello(): print("hello!!!") # 함수 사용 hello() def hello2(): return "hello!!!" print(hello2()) def add(a, b): return a + b result = add(3, 4) print(result) return : ,를 기준으로 리턴값을 여러개 줄수 있음. 다중 리턴은 아님. def sum_and_mul(a, b): return a + b, a * b # 여러개로 return 하지 않고 tuple을 사용해서 리턴됨. print(sum_and_mul(..

dictionary(딕셔너리) 자바의 Map과 같은 개념 key, value를 한 쌍으로 갖는 자료형 key 값을 이용해 value를 찾아냄 {key1 : value1, key2:value2 ...} 파이썬에서 list와 dictionary를 가장 많이 씀 # 생성 dict1 = {"name": "park", "age": 12} dict2 = {0: "Hello Python", 1: "Hello coding"} dict3 = {"arr": [0, 1, 2, 3, 4]} print(dict1) print(dict2) print(dict3) # 딕셔너리에서 원하는 값 가져오기 print(dict1["age"]) # print(dict1["addr"]) # 없는 값을 가져오라고 하면 KeyError: 'add..

list 구조- 자료형(배열과 같은 개념) 대괄호 사용 다양한 형태의 자료들을 담을 수 있음. 자료형을 혼합해도 상관없다. # 생성 list1 = [] list2 = ["a", "b", "c"] list3 = ["a", "b", "c", 1, 2] list4 = [1, 2, 3, 4, 5, 6.5] list5 = [1, 2, ["Life", "is", "short"]] # 2차원 list list6 = list() print(list1) print(list2) print(list3) print(list4) print(list5) print(list6) # 인덱싱 : 하나의 기본 자리 개념이 있음 print("list2[0] : ", list2[0]) print("list3[-1] : ", list3[-1..