Post

Tools: using Jupyter Notebook in VSCode

Jupyter Notebook은 셀 (cell) 단위로 live code, 방정식, 문서등을 작성할 수 있는 편집기이며 웹 베이스의 어플리캐이션으로 Python, Julia, R, Ruby, Scala 등 40여개의 프로그래밍 언어를 별도의 설치 없이 사용 할수 있다.

Jupyter Notebook의 장점으로 코드를 각 셀마다 실행시켜 점진적으로 코드가 추가되는 tutorial 혹은 function의 implementation을 눈으로 쉽게 확인 할 수 있다.

Installation

  1. VSCode를 설치한다.

  2. Anaconda/Miniconda를 설치한다.

  3. Extension .ipynb의 파일을 만들면 VSCode에서 오른쪽 하단에 필요한 Plugins를 설치하라고 알려준다.

    만약 알림이 안뜬다면 Jupyter ExtensionPython Extension을 설치한다.

Shortcuts

단축키기능
Shift + Enter셀 코드 실행
A상위 셀 추가
B하위 셀 추가
D, D셀 삭제
Y셀 코드로 전환
M셀 마크다운 다큐먼트로 전환

Code Example

For Loops

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from requests import get

websites = (
    "google.com",
    "airbnb.com",
    "https://twitter.com",
    "facebook.com",
    "https://tiktok.com"
)

for website in websites:
    if website.startswith("https://"):
        print(website)
    else:
        print("need to fix")

need to fix
need to fix
https://twitter.com
need to fix
https://tiktok.com

URL Formatting

1
2
3
4
for website in websites:
    if not website.startswith("https://"):
        website = f"https://{website}"
    print(website)

https://google.com
https://airbnb.com
https://twitter.com
https://facebook.com
https://tiktok.com

Reference

This post is licensed under CC BY 4.0 by the author.