{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## 01장 파이썬이란 무엇인가?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The Zen of Python, by Tim Peters\r\n", "\r\n", "Beautiful is better than ugly.\r\n", "Explicit is better than implicit.\r\n", "Simple is better than complex.\r\n", "Complex is better than complicated.\r\n", "Flat is better than nested.\r\n", "Sparse is better than dense.\r\n", "Readability counts.\r\n", "Special cases aren't special enough to break the rules.\r\n", "Although practicality beats purity.\r\n", "Errors should never pass silently.\r\n", "Unless explicitly silenced.\r\n", "In the face of ambiguity, refuse the temptation to guess.\r\n", "There should be one-- and preferably only one --obvious way to do it.\r\n", "Although that way may not be obvious at first unless you're Dutch.\r\n", "Now is better than never.\r\n", "Although never is often better than *right* now.\r\n", "If the implementation is hard to explain, it's a bad idea.\r\n", "If the implementation is easy to explain, it may be a good idea.\r\n", "Namespaces are one honking great idea -- let's do more of those!\r\n" ] } ], "source": [ "!python -c \"import this\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 01-1 파이썬 시작하기\n", "\n", "#### 파이썬이란?\n", "\n", "- 파이썬(Python)은 1990년 암스테르담의 귀도 반 로섬이 개발한 인터프리터 언어이다.\n", "- 크리스마스때 만들었다나 뭐라나... 위화감이 느껴지는 대목이다. ^^\n", "\n", "\n", "- 개인적으로 오래 전부터 접할 수 있는 기회가 있었지만, 세미콜론(;)이나 중괄호({})가 없다는 것부터가 진입장벽(?)이었다. ㅎㅎ\n", "- 다시 관심을 갖게된 것은 웹 프레임워크인 Django(장고)나, 최근 데이터 분석에 널리 쓰여서이다.\n", "- 가장 유명한 MOOC 중 하나인 [edX](http://edx.org)에서 사용하는 오픈소스 LMS(Learning Management System) 플랫폼이 장고 기반인 [OpenedX](http://open.edx.org)이다." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 01-2 파이썬의 특징\n", "\n", "- 파이썬은 인간다운 언어이다. - *사람이 생각하는 방식을 그대로 표현할 수 있는 언어이다.*\n", "- 파이썬은 문법이 쉬워 빠르게 배울 수 있다. - *학생들의 코딩 교육에 많이 쓰인다.*\n", "- 파이썬은 무료이지만 강력하다. - *오픈소스이다.*\n", "- 파이썬은 간결하다. - *이러한 간결함이 나에게는 진입장벽이었다.*\n", "- 파이썬은 프로그래밍을 즐기게 해준다. - *평생을 즐겁게 프로그래밍 할 수만 있다면...*\n", "- 파이썬은 개발 속도가 빠르다. - *\"Life is too short, You need python.\"*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 01-3 파이썬으로 무엇을 할 수 있을까?\n", "\n", "#### 파이썬으로 할 수 있는 일\n", "\n", "- 시스템 유틸리티 제작 - *시스템 관리도구나 네트워크 관리도구의 개발*\n", "- GUI 프로그래밍 - *많이 사용하려나??*\n", "- C/C++ 와의 결합 - *멋지다. 이럴만큼 성능에 민감한 프로그램을 개발할 일이 있을런지...*\n", "- **웹 프로그래밍** - *가장 관심이 가는 부분이고 Django(장고) 프레임워크가 있다.*\n", "- 수치 연산 프로그래밍\n", "- 데이터베이스 프로그래밍\n", "- **데이터 분석**, 사물 인터넷 - *요즘 R과 함께 데이터 분석에 많이 쓰이고 있다.*\n", "\n", "#### 파이썬으로 할 수 없는 일\n", "\n", "- 시스템과 밀접한 프로그래밍 영역\n", "- 모바일 프로그래밍" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 01-4 파이썬 설치하기\n", "\n", "- [위키독스](https://wikidocs.net/8) 참고\n", "- 윈도우의 경우라면 공식 홈페이지의 [다운로드 페이지](http://www.python.org/downloads)에서 내려받아 설치한다.\n", "- 리눅스 사용자라면 기본적으로 설치되어 있을 것이다.\n", "- 다른 버전을 설치하려면 위의 다운로드 페이지에서 내려받아 소스를 컴파일하여 설치할 수 있다.\n", "- OS 별 패키지 매니저를 사용하여 설치할 수도 있다.\n", "\n", "\n", "- 개인적으로는 \"설치가 필요 없는 클라우드 통합개발환경\"인 [구름IDE](http://ide.goorm.io/)를 사용해 보려고 한다.\n", "- 현재 사용하고 있는 jupyter 노트북도 구름IDE 에서 제공하고 있는 컨테이너 환경이다." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 01-5 파이썬 둘러보기\n", "\n", "#### 파이썬 기초 문법 따라 해보기\n", "\n", "- 사칙연산" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1+2" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.25" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3 / 2.4" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "27" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3 * 9" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 변수에 숫자 대입하고 계산하기" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = 1\n", "b = 2\n", "a + b" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 변수에 문자 대입하고 출력하기" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python\n" ] } ], "source": [ "a = \"Python\"\n", "print(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 파이썬은 **복소수**도 지원한다." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(6+9j)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = 2 + 3j\n", "b = 3\n", "a * b" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 조건문 if" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a is greater than 1\n" ] } ], "source": [ "a = 3\n", "if a > 1:\n", " print(\"a is greater than 1\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 반복문 for" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n" ] } ], "source": [ "for a in [1, 2, 3]:\n", " print(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 반복문 while" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n" ] } ], "source": [ "i = 0\n", "while i < 3:\n", " i = i + 1\n", " print(i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 함수" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "7\n" ] } ], "source": [ "def sum(a, b):\n", " return a+b\n", "\n", "print(sum(3, 4))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 2 }