-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
7,859 additions
and
17 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,392 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"nbpresent": { | ||
"id": "904e7041-5347-4036-bfff-4b5af4763913" | ||
}, | ||
"slideshow": { | ||
"slide_type": "slide" | ||
} | ||
}, | ||
"source": [ | ||
"# Python 程式設計教學\n", | ||
"\n", | ||
"## Victor Gau\n", | ||
"\n", | ||
"### [[email protected]](\"mailto:[email protected]?subject=[Question]QF20170311\")\n", | ||
"\n", | ||
"### 2017-03-11\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"slideshow": { | ||
"slide_type": "slide" | ||
} | ||
}, | ||
"source": [ | ||
"# Python 的變數" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"source": [ | ||
"## 變數的命名規則\n", | ||
"\n", | ||
"* 變數名稱最好以英文字母或底線做開頭 (數字不能做開頭)\n", | ||
" - \\_variable, variable, variable\\_ \n", | ||
"* 除開頭字元外,其他字元使用數字、底線、或英文字母\n", | ||
" - _var123, var_123\n", | ||
"* 變數會區分大小寫\n", | ||
"* 避開 keywords\n", | ||
"* 避開 [built-in objects](https://docs.python.org/3/library/builtins.html)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"字串 = \"Hello World!\"\n", | ||
"\n", | ||
"print(字串)\n", | ||
"\n", | ||
"# 咦... 可以用中文變數耶!!!\n", | ||
"\n", | ||
"# 但是請不要這樣用,因為在使用很多套件時,這樣的變數名稱可能會造成問題。" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import string\n", | ||
"\n", | ||
"# help(string)\n", | ||
"\n", | ||
"# ?string\n", | ||
"\n", | ||
"string.ascii_letters" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Keywords\n", | ||
"\n", | ||
"import keyword\n", | ||
"\n", | ||
"print(keyword.kwlist)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# https://docs.python.org/3/reference/executionmodel.html\n", | ||
"\n", | ||
"# built-in objects\n", | ||
"\n", | ||
"# Python 2.7.x\n", | ||
"#import __builtin__\n", | ||
"#\n", | ||
"#dir(__builtin__)\n", | ||
"\n", | ||
"# Python 3.5\n", | ||
"\n", | ||
"import builtins\n", | ||
"\n", | ||
"print(dir(builtins))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"source": [ | ||
"### 兩個好用的函數:\n", | ||
"\n", | ||
"* type()\n", | ||
"* dir()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# 使用 type() 列出變數型別\n", | ||
"\n", | ||
"a = 1\n", | ||
"\n", | ||
"type(a)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "fragment" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"b = '123'\n", | ||
"\n", | ||
"type(b)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# 使用 dir() 列出 local scope 裡面有那些變數或模組等\n", | ||
"dir()\n", | ||
"\n", | ||
"# 關於 magic methods\n", | ||
"# http://minhhh.github.io/posts/a-guide-to-pythons-magic-methods" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# 使用 dir(module) 列出模組可以使用的屬性及方法等\n", | ||
"\n", | ||
"dir(sys)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "subslide" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# 使用 dir() 列出物件的方法及屬性\n", | ||
"\n", | ||
"print(dir(b))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "fragment" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"c = [1, 2, 3]\n", | ||
"\n", | ||
"type(c)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"slideshow": { | ||
"slide_type": "fragment" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(dir(c))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"anaconda-cloud": {}, | ||
"celltoolbar": "Slideshow", | ||
"kernelspec": { | ||
"display_name": "Python [default]", | ||
"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.5.2" | ||
}, | ||
"livereveal": { | ||
"scroll": true | ||
}, | ||
"nbpresent": { | ||
"slides": {}, | ||
"themes": { | ||
"default": "56b38c57-4ffe-478a-9f92-8ca64a17c67c", | ||
"theme": { | ||
"56b38c57-4ffe-478a-9f92-8ca64a17c67c": { | ||
"id": "56b38c57-4ffe-478a-9f92-8ca64a17c67c", | ||
"palette": { | ||
"19cc588f-0593-49c9-9f4b-e4d7cc113b1c": { | ||
"id": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", | ||
"rgb": [ | ||
252, | ||
252, | ||
252 | ||
] | ||
}, | ||
"31af15d2-7e15-44c5-ab5e-e04b16a89eff": { | ||
"id": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", | ||
"rgb": [ | ||
68, | ||
68, | ||
68 | ||
] | ||
}, | ||
"50f92c45-a630-455b-aec3-788680ec7410": { | ||
"id": "50f92c45-a630-455b-aec3-788680ec7410", | ||
"rgb": [ | ||
155, | ||
177, | ||
192 | ||
] | ||
}, | ||
"c5cc3653-2ee1-402a-aba2-7caae1da4f6c": { | ||
"id": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", | ||
"rgb": [ | ||
43, | ||
126, | ||
184 | ||
] | ||
}, | ||
"efa7f048-9acb-414c-8b04-a26811511a21": { | ||
"id": "efa7f048-9acb-414c-8b04-a26811511a21", | ||
"rgb": [ | ||
25.118061674008803, | ||
73.60176211453744, | ||
107.4819383259912 | ||
] | ||
} | ||
}, | ||
"rules": { | ||
"blockquote": { | ||
"color": "50f92c45-a630-455b-aec3-788680ec7410" | ||
}, | ||
"code": { | ||
"font-family": "Anonymous Pro" | ||
}, | ||
"h1": { | ||
"color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", | ||
"font-family": "Lato", | ||
"font-size": 8 | ||
}, | ||
"h2": { | ||
"color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", | ||
"font-family": "Lato", | ||
"font-size": 6 | ||
}, | ||
"h3": { | ||
"color": "50f92c45-a630-455b-aec3-788680ec7410", | ||
"font-family": "Lato", | ||
"font-size": 5.5 | ||
}, | ||
"h4": { | ||
"color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", | ||
"font-family": "Lato", | ||
"font-size": 5 | ||
}, | ||
"h5": { | ||
"font-family": "Lato" | ||
}, | ||
"h6": { | ||
"font-family": "Lato" | ||
}, | ||
"h7": { | ||
"font-family": "Lato" | ||
}, | ||
"pre": { | ||
"font-family": "Anonymous Pro", | ||
"font-size": 4 | ||
} | ||
}, | ||
"text-base": { | ||
"font-family": "Merriweather", | ||
"font-size": 4 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Oops, something went wrong.