{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**Hello,World**" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, World!\n" ] } ], "source": [ "print (\"Hello, World!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 数字和表达式" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 加法" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2+2" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "288925" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "53672+235253" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1/2" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1.0/2.0" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1/2.0" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1/2." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from __future__ import division\n", "1/2" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1//2" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1.0//2.0" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1%2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 普通除法 " ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.3333333333333335" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "10/3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 整除" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "10//3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 取余(模除)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "10%3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** 乘法 **" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 * 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 乘方" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 ** 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 十六进制" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "175" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0xAF" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 八进制" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0o10" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 二进制" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0b11" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 变量" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "x = 2" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x * 2" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [], "source": [ "y = x" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "x = 1" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 语句" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 * 2" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n" ] } ], "source": [ "print (2*2)" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The meaning of life:42\n" ] }, { "data": { "text/plain": [ "'42'" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "input(\"The meaning of life:\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 获取用户输入" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x:2\n" ] } ], "source": [ "x = input(\"x:\")" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "y:3\n" ] } ], "source": [ "y = input(\"y:\")" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [], "source": [ "x= int(x)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [], "source": [ "y = int(y)" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "6\n" ] } ], "source": [ "print (x*y)" ] }, { "cell_type": "code", "execution_count": 89, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "One equals One\n" ] } ], "source": [ "if 1==2:\n", " print('One equals Two')\n", "if 1 ==1:\n", " print('One equals One')\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 函数\n" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 ** 3" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pow(2,3)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(-10)" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(1.0/2.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 模块" ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "32" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import math \n", "math.floor(32.9)" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "32.0" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "float(math.floor(32.9))" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.0" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from math import sqrt\n", "sqrt(9)" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(sqrt(9))" ] }, { "cell_type": "code", "execution_count": 106, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1j" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import cmath\n", "cmath.sqrt(-1)" ] }, { "cell_type": "code", "execution_count": 107, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(-3+31j)" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1+3j)*(9+4j)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 字符串" ] }, { "cell_type": "code", "execution_count": 108, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hello,Python'" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"Hello,Python\"" ] }, { "cell_type": "code", "execution_count": 109, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hello,Python'" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'Hello,Python'" ] }, { "cell_type": "code", "execution_count": 119, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"let's go!\"" ] }, "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"let\\'s go!\"" ] }, { "cell_type": "code", "execution_count": 111, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'\"Hello,Pyrhon\"'" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\\\"Hello,Pyrhon\\\"\"" ] }, { "cell_type": "code", "execution_count": 120, "metadata": {}, "outputs": [], "source": [ "x= 'Hello,Python,'" ] }, { "cell_type": "code", "execution_count": 113, "metadata": {}, "outputs": [], "source": [ "y= \"let\\'s go!\"" ] }, { "cell_type": "code", "execution_count": 117, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello,Python,let's go!'\n" ] } ], "source": [ "print(x+y)\n" ] }, { "cell_type": "code", "execution_count": 123, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"'Hello,World!'\"" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "repr(\"Hello,World!\")" ] }, { "cell_type": "code", "execution_count": 124, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'hello,World!'" ] }, "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ "str(\"hello,World!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 新函数" ] }, { "cell_type": "code", "execution_count": 125, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(-10)" ] }, { "cell_type": "code", "execution_count": 126, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3j" ] }, "execution_count": 126, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cmath.sqrt(-9)" ] }, { "cell_type": "code", "execution_count": 127, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.0" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "float(3)" ] }, { "cell_type": "code", "execution_count": 128, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Welcome to Python 3.6's help utility!\n", "\n", "If this is your first time using Python, you should definitely check out\n", "the tutorial on the Internet at https://docs.python.org/3.6/tutorial/.\n", "\n", "Enter the name of any module, keyword, or topic to get help on writing\n", "Python programs and using Python modules. To quit this help utility and\n", "return to the interpreter, just type \"quit\".\n", "\n", "To get a list of available modules, keywords, symbols, or topics, type\n", "\"modules\", \"keywords\", \"symbols\", or \"topics\". Each module also comes\n", "with a one-line summary of what it does; to list the modules whose name\n", "or summary contain a given string such as \"spam\", type \"modules spam\".\n", "\n", "help> abs\n", "Help on built-in function abs in module builtins:\n", "\n", "abs(x, /)\n", " Return the absolute value of the argument.\n", "\n", "help> \n", "\n", "You are now leaving help and returning to the Python interpreter.\n", "If you want to ask for help on a particular object directly from the\n", "interpreter, you can type \"help(object)\". Executing \"help('string')\"\n", "has the same effect as typing a particular string at the help> prompt.\n" ] } ], "source": [ "help()" ] }, { "cell_type": "code", "execution_count": 130, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello,Python,a\n" ] }, { "data": { "text/plain": [ "'a'" ] }, "execution_count": 130, "metadata": {}, "output_type": "execute_result" } ], "source": [ "input(x)" ] }, { "cell_type": "code", "execution_count": 131, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(3.0)" ] }, { "cell_type": "code", "execution_count": 137, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.ceil(2.5)" ] }, { "cell_type": "code", "execution_count": 138, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.floor(2.5)" ] }, { "cell_type": "code", "execution_count": 139, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.0" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.sqrt(9)" ] }, { "cell_type": "code", "execution_count": 140, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pow(2,3)" ] }, { "cell_type": "code", "execution_count": 145, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"'Hello,World!'\"" ] }, "execution_count": 145, "metadata": {}, "output_type": "execute_result" } ], "source": [ "repr(\"Hello,World!\")" ] }, { "cell_type": "code", "execution_count": 146, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(2.21323531453465)" ] }, { "cell_type": "code", "execution_count": 147, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hello,World~'" ] }, "execution_count": 147, "metadata": {}, "output_type": "execute_result" } ], "source": [ "str(\"Hello,World~\")" ] } ], "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.7.0" } }, "nbformat": 4, "nbformat_minor": 2 }