Created
June 29, 2014 15:24
-
-
Save bryanyang0528/8c63e8a34726d33c56fe to your computer and use it in GitHub Desktop.
Python Basic
This file contains hidden or 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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:65f47926354c8a7ea76eb54818c1f9122dbeb0aeb2e38b2768d96b18c5b7be19" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"\u57fa\u672c\u8a9e\u6cd5" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#\u9019\u662fJAVA\u7684HELLO WORLD!\n", | |
"\"\"\"\n", | |
"class HelloWorldApp {\n", | |
" public static void main(String[] args) {\n", | |
" System.out.println(\"Hello World!\"); // Display the string.\n", | |
" }\n", | |
"}\n", | |
"\"\"\"\n", | |
"\n", | |
"#\u9019\u662fPTHON\u7684HELLO WORLD\n", | |
"print \"Hello World!\"" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Hello World!\n" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# python \u4e0d\u9700\u8981\u5148\u6307\u5b9a\u8b8a\u9805\u578b\u614b\n", | |
"my_int = 7\n", | |
"my_float = 1.23\n", | |
"my_bool = True\n", | |
"\n", | |
"print my_int \n", | |
"print my_float\n", | |
"print my_bool\n", | |
"print my_int * my_float" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"7\n", | |
"1.23\n", | |
"True\n", | |
"8.61\n" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Python\u900f\u904e\":\"\u548c\u7e2e\u6392\u4f86\u7ba1\u7406\u8a9e\u6cd5\n", | |
"def spam():\n", | |
" eggs = 12\n", | |
" return eggs\n", | |
"print spam()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"12\n" | |
] | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# +-*/\n", | |
"\n", | |
"print 5 + 2 + 8\n", | |
"print 5 - 2 - 8\n", | |
"print 5 * 2 * 8\n", | |
"print 5 / 2 + 8\n", | |
"\n", | |
"## \u96a8\u8457\u6578\u5165\u6578\u503c\u800c\u81ea\u52d5\u6539\u8b8a\u8b8a\u9805\u578b\u614b\n", | |
"print 5.0 / 2 +8\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"15\n", | |
"-5\n", | |
"80\n", | |
"10\n", | |
"10.5\n" | |
] | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"\u5b57\u4e32\u5c31\u662f\u9663\u5217" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"my_name = \"Bryan\"\n", | |
"print my_name" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Bryan\n" | |
] | |
} | |
], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#\u8df3\u812b\u5b57\u5143 \\'\n", | |
"\n", | |
"my_blog = 'Bryan's \u884c\u92b7\u7814\u7a76\u53ca\u8cc7\u6599\u5206\u6790\u7b46\u8a18'\n", | |
"print my_blog" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "SyntaxError", | |
"evalue": "invalid syntax (<ipython-input-18-81e24fb25f39>, line 2)", | |
"output_type": "pyerr", | |
"traceback": [ | |
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-18-81e24fb25f39>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m my_blog = 'Bryan's \u884c\u92b7\u7814\u7a76\u53ca\u8cc7\u6599\u5206\u6790\u7b46\u8a18'\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" | |
] | |
} | |
], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"\n", | |
"# \u6709\u95dc\u4e2d\u6587encode\u7684\u554f\u984c\u53ef\u4ee5\u53c3\u8003\u4e0b\u65b9\u9023\u7d50\n", | |
"# http://blog.wahahajk.com/2009/08/unicodedecodeerror-ascii-codec-cant.html\n", | |
"\n", | |
"# index \u5f9e0\u958b\u59cb\n", | |
"my_blog = u'Bryan\\'s \u884c\u92b7\u7814\u7a76\u53ca\u8cc7\u6599\u5206\u6790\u7b46\u8a18'\n", | |
"B = my_blog[0]\n", | |
"print B\n", | |
"\n", | |
"\n", | |
" " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"B\n" | |
] | |
} | |
], | |
"prompt_number": 40 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# \u8df3\u812b\u5b57\u5143\u4e0d\u5360\u4f4d\u7f6e \u7a7a\u767d\u5360\u4f4d\u7f6e\n", | |
"pos = 0\n", | |
"for i in my_blog:\n", | |
" print pos, i\n", | |
" pos += 1" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"0 B\n", | |
"1 r\n", | |
"2 y\n", | |
"3 a\n", | |
"4 n\n", | |
"5 '\n", | |
"6 s\n", | |
"7 \n", | |
"8 \u884c\n", | |
"9 \u92b7\n", | |
"10 \u7814\n", | |
"11 \u7a76\n", | |
"12 \u53ca\n", | |
"13 \u8cc7\n", | |
"14 \u6599\n", | |
"15 \u5206\n", | |
"16 \u6790\n", | |
"17 \u7b46\n", | |
"18 \u8a18\n" | |
] | |
} | |
], | |
"prompt_number": 41 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# string \u7684 method\n", | |
"# len()\n", | |
"# lower()\n", | |
"# upper()\n", | |
"\n", | |
"print len(my_blog)\n", | |
"print my_blog.lower()\n", | |
"print my_blog.upper()\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"19\n", | |
"bryan's \u884c\u92b7\u7814\u7a76\u53ca\u8cc7\u6599\u5206\u6790\u7b46\u8a18\n", | |
"BRYAN'S \u884c\u92b7\u7814\u7a76\u53ca\u8cc7\u6599\u5206\u6790\u7b46\u8a18\n" | |
] | |
} | |
], | |
"prompt_number": 46 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# \u96d6\u7136PYTHON\u5b9a\u7fa9\u8b8a\u9805\u6642\u4e0d\u9808\u6307\u5b9a\u8b8a\u9805\u578b\u614b \n", | |
"# \u4f46\u662f\u5728\u64cd\u4f5c\u4e0a\u9084\u662f\u9700\u8981\u6ce8\u610f\u8b8a\u9805\u578b\u614b\n", | |
"\n", | |
"x = 19\n", | |
"\n", | |
"print x\n", | |
"#print \"\u767d\u718a\u7684\u5e74\u9f61\u662f? \" + x + \"\u6b72\" \n", | |
"print \"\u767d\u718a\u7684\u5e74\u9f61\u662f? \" + str(x) + \"\u6b72\"" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"19\n", | |
"\u767d\u718a\u7684\u5e74\u9f61\u662f? 19\u6b72\n" | |
] | |
} | |
], | |
"prompt_number": 51 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment