파이썬 설치
1. 원하는 버전 다운로드
Download Python
The official home of the Python Programming Language
www.python.org
2. path에 추가시키기 위해 체크
3. 환경변수에 path들어갔나 확인
4. cmd에서 python이라고 쳤을 때 버전 정보 나오면 설치 성공
pycharm editor 설치(https://www.jetbrains.com/pycharm/download/#section=windows)
1. 계속 next누르다 다음과 같은 화면 나오면 원하는 곳에 체크 누른뒤 계속 next
2. python interpreter설정
- file > setting > python interpreter 검색
- 오른쪽 톱니바퀴 버튼 > add 버튼 클릭
- existing environment 선택
- 자신이 지정한 python 경로로 이동 > python.exe선택
- 파이썬 참조 문서 링크
https://docs.python.org/3/tutorial/index.html
The Python Tutorial — Python 3.8.4rc1 documentation
The Python Tutorial Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its i
docs.python.org
https://docs.python.org/3/library/index.html
The Python Standard Library — Python 3.8.4rc1 documentation
The Python Standard Library While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the opt
docs.python.org
- 파이썬 웹스크레이핑(데이터 크롤링)에 사용 --> 인공지능, 머신러닝
- 써드(third)파트라이브러리 : 위와 같은 것을 사용하기 위해선 라이브러리 필요
- python charm 프로젝트 생성
- cmd 창에서 python코딩
변수 선언 : 데이터형 쓰지 않음 --> 자동으로 데이터형 매칭
타입 확인 : type(변수명)
종료 : exit() 함수
- 교재 시작
- 교재 중요부분 체크
- open API사용 위해 공공데이터 포털 페이지 참조 : https://data.go.kr/
공공데이터 포털
국가에서 보유하고 있는 다양한 데이터를『공공데이터의 제공 및 이용 활성화에 관한 법률(제11956호)』에 따라 개방하여 국민들이 보다 쉽고 용이하게 공유•활용할 수 있도록 공공데이터(Datase
data.go.kr
파이썬, 자바스크립트 - 동적 프로그래밍
자바 - 정적프로그래밍
- 파이썬 특징
- 동적 프로그래밍
- 객체지향 언어
- IOT와 같은 장비 제어
- 웹서버 어플리케이션 - Django, Flask
- 풍부한 라이브러리
- 유니코드 - 문자열이 모두 유니코드로 나타남
- 자료형과 연산자
** 산술연산
소숫점이 없는 정수 - int
소숫점이 있는 숫자 - float
num = 100
print(num)
100
num
100
myfloat = 3.14
myfloat
3.14
num + myfloat
103.14
num - myfloat
96.86
num * myfloat
314.0
num % myfloat
2.659999999999996
int(myfloat)
3
** 변수명
- 변수명 지정 X
- 숫자는 처음에 올 수 X
- 예약어 사용 X
: 제어문/예외(try, catch excetion, finally, raise...)/연산자(and, not, or...)/함수(class, lambda, def...)/모듈로드(import,from...) 등
(and, as, assert, break, class, continue, def, del, elif, else, except, is, finally, for, from, global, if, import, in, lambda, nonlocal, not, or, pass, raise, return, try, while, with, yield)
- id함수 : 주소값 출력
x = 100
id(x)
140704361909616
- 주석
#한줄주석
'''
block주석
사칙연산
실행 : ctrl + shift + f10
주석 : 범위잡고(shift + 방향키) + ctrl + /
'''
#자바에서 + 는 연결 BUT 파이썬 에서는 연산
n1 = 100
n2 = 200
print('n1 = ', n1, n2) #결과 : n1 = 100 200
print(n1+n2) #결과 : 300
mystr = 'hello'
mystr2 = "hello"
print(mystr, mystr2) #결과 : hello hello
print(mystr + mystr2) #결과 : hellohello
- CLI(Command Line Interface) : GUI와 달리 터미널에서 직접 명령어 입력하는 것
- Input() 함수
'''
Input함수를 사용해 사용자로부터 입력을 받는다.
'''
print("이름을 입력해주세요")
name = input()
print(type(name))
print('Hello',name)
print('온도를 입력하세요')
ondo = float(input())
print(type(ondo))
print('입력한 온도 값은',ondo)
- 포맷팅
- 숫자는 원래 왼쪽을 띄우고 오른쪽 부터 채움
- 문자열은 원래 오른쪽을 띄우고 왼쪽 부터 채우지만 오른쪽 정렬을 하고 싶을 땐 부등호(>)를 사용하면 된다.
# 1. %formatting : c언어 스타일
# 2. string format 함수 : {}에 대응하는 값을 format()의 인자로 전달
# 3. f-string : python3.6 이상에서만 사용
temperature = 36
print('1. 온도값은 %d %.2f' % (temperature, temperature))
print('2. 온도값은 {}'.format(temperature))
print(f'3. 온도값은 {temperature}')
print("Art : %5d, Prince per Uint: %8.2f" % (453, 59.058))
print("Art : %d, Prince per Uint: %.2f" % (453, 59.058))
print("Art : {0:5d}, Prince per Unit : {1:8.2f}".format(453, 59.058))
print("Art : {0:d}, Prince per Unit : {1:.2f}".format(453, 59.058))
print("Product: %5s, Prince per unit: %.5f" % ("Apple", 5.243))
print("Product: {0:10s}, Price per unit: {1:10.3f}.".format("Apple", 5.243))
print("Product: {0:>10s}, Price per unit: {1:10.3f}.".format("Apple", 5.243))
print("Product: {name:>10s}, Price per unit: {price:10.3f}.".format(name="APPLE", price=5.243))
- 파일 읽기
file = open('파일명','상태') //파일 열기
file.readline() //한줄씩 읽기
file.close //파일 닫기
'''
yesterday.txt 파일을 읽어서
'YESTERDAY', 'yesterday', 'Yesterday 단어가 몇 번 나오는지 Counting 해보기'
'''
# file open
# mode : r(read), w(write), a(append)
# 이미지 등 파일 읽을 때 : rb(read binary), wb(write Binary)
file = open('yesterday.txt', 'r')
# file의 내용을 읽은 값을 저장한 변수
yesterday_lyric = ''
while 1:
line = file.readline()
if not line:
break
yesterday_lyric += line.strip() + '\n'
print(yesterday_lyric)
print(len(yesterday_lyric))
n_of_YESTERDAY = yesterday_lyric.upper().count('YESTERDAY')
print(n_of_YESTERDAY)
n_of_yesterday = yesterday_lyric.lower().count('yesterday')
print(n_of_yesterday)
n_of_Yesterday = yesterday_lyric.count('Yesterday')
print(n_of_Yesterday)
file.close()
- 리스트
- 원하는 모든 데이터를 담는 컨테이너
- Read-Only 리스트 - 튜플(Tuples)
- 파이썬은 여러가지 데이터 형을 담을 수 있다.
colors = ["red", "blue", "green"]
print(colors[0])
print(colors[2])
print(len(colors))
# lsit 0번째 엘리먼트 값을 변경하기
colors[0] = 'Yellow'
print(colors)
# list에 엘리먼트를 1개씩 추가하기
colors.append('black')
print(colors)
# list에 엘리만트를 여러개 추가하기
colors.extend(['orange', 'red'])
print(colors)
# list의 엘리먼트 삭제하기
# remove('값'), del colors[인덱스]
colors.remove('black')
print(colors)
del colors[0]
print(colors)
# 지정하는 인덱스에 item을 삽입하기
colors.insert(1, 'Yellow')
print(colors)
names = ["python", "java", "scalar"]
# 리스트의 연산
print(names * 2)
print(colors + names)
print(colors)
# slicing을 사용해서 삭제하기
del colors[:2]
print(colors)
# 값으로 index 찾기
print(colors.index('red'))
# in 구문 - 해당 값이 있으면 True, 없으면 False
print('java' in names) #True
print('kotlin' in names) #False
print('python' not in names) #True
# 해당값이 몇개 있는지를 카운팅하기
print(names.count('java')) #1개
cities = ["서울", "부산", "인천", "대구", "대전", "광주", "울산", "수원"]
print(cities[0:6]) # 0~5
print(cities[0:6:2]) # 두개단위 건너뜀
print(cities[::-1]) # 역순
print(cities[:]) #all
print(cities[-50:50]) #all
print(cities[::2], " AND ", cities[::-1]) #두개단위 and 역순
- 과제
**7월 14일 화
: 1장 ~ 4장 - 파이썬, 변수, 타입, 연산자 + 연습문제
**7월 15일 수
: 5장 ~ 10장 - 조건문, 반복문, 함수, 문자열관리, 리스트와 튜플, 사전과집합,
**7월 16일 목, 금, 토
: SQL, html, css selector(css 선택자)
다음주에 사용할 python open source
1. pandas : tablet data(표데이터) 처리
2. requests : http client
3. beautifulsoup : html, xml 데이터 parsing
4. matplotlib : visualization(시각화)
5. seaborn : visualization(시각화)
6. pymysql : mysql db connector
7. sqlalchemy : ORM 기능
ORM(Object Relationship Mapping)
**7월 20일 월
: 14장 ~ 15장 - 파일, 클래스(*)
**7월 21일 화
: 16장 ~ 17장 - 모듈과패키지, 고급문법
'Python > Python 웹 크롤링' 카테고리의 다른 글
파이썬 OpenAPI_07월 21일 (0) | 2020.07.21 |
---|---|
파이썬 OpenAPI_07월 20일 (0) | 2020.07.20 |
파이썬 수업_07월 17일 (0) | 2020.07.17 |
파이썬 수업_07월 16일 (0) | 2020.07.16 |
파이썬 수업_07월15일 (0) | 2020.07.15 |