study

(210616) Python 수업 첫날

hjkeeeem 2024. 7. 25. 20:18

대부분 snake_case ( 소문자_언더바)

클래스명은 camel case (두 단어를 합쳤을 때 첫문자는 대문자)

 

 

파이썬 배포판들 중의 하나인 아나콘다 설치

- 배포판을 설치해도 언어(Language), 가상머신(Virtual machine), API 등이 같다.

anaconda download 하기

https://www.anaconda.com/products/individual

 

Anaconda | Individual Edition

Anaconda's open-source Individual Edition is the easiest way to perform Python/R data science and machine learning on a single machine.

www.anaconda.com

 

cmd로 Jupyter notebook들어가는 방법 ( 내가 원하는 경로로 들어가기 위해 사용)

-1-

cd C:\dev\JupyterNotebook

jupyter notebook

 

-2-

dir

cd dev

cd jupyternotebook

 

저장한 뒤 폴더 안의 apfhd.txt파일에서 .txt를 지워 확장자를 변경해준다. 

 

 

Edit 툴

▶ Jupyter는 명령모드(파란색)와 편집모드(초록색)가 있다.

▶ dd <- 셀 삭제

▶ esc <- 편집 모드에서 누르면 명령모드로 변경

▶ esc + a <- 추가하는 셀을 가장 위에 올리고 싶을 때 사용

▶ ctrl + enter <- 그냥 실행

▶ alt + enter <- 그냥 셀 추가

▶ shift + enter <- 실행 후 셀 추가

 

문자열 루프를 사용하여 하나씩 나타내기

for x in "banana":
  print(x)

 

 

슬라이싱 문자열

위치 2에서 위치 5 (포함되지 않음)로 문자를 가져옵니다.

b = "Hello, World!"
print(b[2:5])

 

출력 결과 : llo

 

형식 문자열

fruits = ["apple", "banana", "cherry", "kiwi", "mango"]

newlist = [x if x != "banana" else "orange" for x in fruits]

print(newlist)

 

==> fruits에 바나나가 없을 때가 참 이라는 뜻

하지만 fruits에는 바나나가 있기 때문에 else로 넘어가서 banana를 orange로 바꿔주는 것