mirror of
https://github.com/apachecn/ailearning.git
synced 2026-05-03 10:01:56 +08:00
2020-10-19 21:08:55
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
通常我们并不使用**Python**自带的解释器,而是使用另一个比较方便的解释器——**ipython**解释器,命令行下输入:
|
||||
|
||||
```
|
||||
```py
|
||||
ipython
|
||||
```
|
||||
|
||||
@@ -14,12 +14,12 @@ ipython
|
||||
|
||||
In [1]:
|
||||
|
||||
```
|
||||
```py
|
||||
print "hello, world"
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
hello, world
|
||||
|
||||
```
|
||||
@@ -28,7 +28,7 @@ hello, world
|
||||
|
||||
In [2]:
|
||||
|
||||
```
|
||||
```py
|
||||
a = 1
|
||||
|
||||
```
|
||||
@@ -37,20 +37,20 @@ a = 1
|
||||
|
||||
In [3]:
|
||||
|
||||
```
|
||||
```py
|
||||
a
|
||||
|
||||
```
|
||||
|
||||
Out[3]:
|
||||
|
||||
```
|
||||
```py
|
||||
1
|
||||
```
|
||||
|
||||
In [4]:
|
||||
|
||||
```
|
||||
```py
|
||||
b = [1, 2, 3]
|
||||
|
||||
```
|
||||
@@ -63,14 +63,14 @@ b = [1, 2, 3]
|
||||
|
||||
In [5]:
|
||||
|
||||
```
|
||||
```py
|
||||
%lsmagic
|
||||
|
||||
```
|
||||
|
||||
Out[5]:
|
||||
|
||||
```
|
||||
```py
|
||||
Available line magics:
|
||||
%alias %alias_magic %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %install_default_config %install_ext %install_profiles %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %popd %pprint %precision %profile %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode
|
||||
|
||||
@@ -90,12 +90,12 @@ Automagic is ON, % prefix IS NOT needed for line magics.
|
||||
|
||||
In [6]:
|
||||
|
||||
```
|
||||
```py
|
||||
%whos
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Variable Type Data/Info
|
||||
----------------------------
|
||||
a int 1
|
||||
@@ -107,7 +107,7 @@ b list n=3
|
||||
|
||||
In [7]:
|
||||
|
||||
```
|
||||
```py
|
||||
%reset -f
|
||||
|
||||
```
|
||||
@@ -116,12 +116,12 @@ In [7]:
|
||||
|
||||
In [8]:
|
||||
|
||||
```
|
||||
```py
|
||||
%whos
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Interactive namespace is empty.
|
||||
|
||||
```
|
||||
@@ -130,14 +130,14 @@ Interactive namespace is empty.
|
||||
|
||||
In [9]:
|
||||
|
||||
```
|
||||
```py
|
||||
%pwd
|
||||
|
||||
```
|
||||
|
||||
Out[9]:
|
||||
|
||||
```
|
||||
```py
|
||||
u'C:\\Users\\lijin\\Documents\\Git\\python-tutorial\\01\. python tools'
|
||||
```
|
||||
|
||||
@@ -145,7 +145,7 @@ u'C:\\Users\\lijin\\Documents\\Git\\python-tutorial\\01\. python tools'
|
||||
|
||||
In [10]:
|
||||
|
||||
```
|
||||
```py
|
||||
%mkdir demo_test
|
||||
|
||||
```
|
||||
@@ -154,12 +154,12 @@ In [10]:
|
||||
|
||||
In [11]:
|
||||
|
||||
```
|
||||
```py
|
||||
%cd demo_test/
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
C:\Users\lijin\Documents\Git\python-tutorial\01\. python tools\demo_test
|
||||
|
||||
```
|
||||
@@ -168,13 +168,13 @@ C:\Users\lijin\Documents\Git\python-tutorial\01\. python tools\demo_test
|
||||
|
||||
In [12]:
|
||||
|
||||
```
|
||||
```py
|
||||
%%writefile hello_world.py
|
||||
print "hello world"
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Writing hello_world.py
|
||||
|
||||
```
|
||||
@@ -183,12 +183,12 @@ Writing hello_world.py
|
||||
|
||||
In [13]:
|
||||
|
||||
```
|
||||
```py
|
||||
%ls
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
驱动器 C 中的卷是 System
|
||||
卷的序列号是 DC4B-D785
|
||||
|
||||
@@ -206,12 +206,12 @@ In [13]:
|
||||
|
||||
In [14]:
|
||||
|
||||
```
|
||||
```py
|
||||
%run hello_world.py
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
hello world
|
||||
|
||||
```
|
||||
@@ -220,7 +220,7 @@ hello world
|
||||
|
||||
In [15]:
|
||||
|
||||
```
|
||||
```py
|
||||
import os
|
||||
os.remove('hello_world.py')
|
||||
|
||||
@@ -230,12 +230,12 @@ os.remove('hello_world.py')
|
||||
|
||||
In [16]:
|
||||
|
||||
```
|
||||
```py
|
||||
%ls
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
驱动器 C 中的卷是 System
|
||||
卷的序列号是 DC4B-D785
|
||||
|
||||
@@ -252,12 +252,12 @@ In [16]:
|
||||
|
||||
In [17]:
|
||||
|
||||
```
|
||||
```py
|
||||
%cd ..
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
C:\Users\lijin\Documents\Git\python-tutorial\01\. python tools
|
||||
|
||||
```
|
||||
@@ -266,7 +266,7 @@ C:\Users\lijin\Documents\Git\python-tutorial\01\. python tools
|
||||
|
||||
In [18]:
|
||||
|
||||
```
|
||||
```py
|
||||
%rmdir demo_test
|
||||
|
||||
```
|
||||
@@ -275,12 +275,12 @@ In [18]:
|
||||
|
||||
In [19]:
|
||||
|
||||
```
|
||||
```py
|
||||
%hist
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
print "hello, world"
|
||||
a = 1
|
||||
a
|
||||
@@ -311,7 +311,7 @@ os.remove('hello_world.py')
|
||||
|
||||
In [20]:
|
||||
|
||||
```
|
||||
```py
|
||||
sum?
|
||||
|
||||
```
|
||||
@@ -320,7 +320,7 @@ sum?
|
||||
|
||||
In [21]:
|
||||
|
||||
```
|
||||
```py
|
||||
# 导入numpy和matplotlib两个包
|
||||
%pylab
|
||||
# 查看其中sort函数的帮助
|
||||
@@ -328,7 +328,7 @@ sort??
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Using matplotlib backend: Qt4Agg
|
||||
Populating the interactive namespace from numpy and matplotlib
|
||||
|
||||
@@ -340,7 +340,7 @@ Populating the interactive namespace from numpy and matplotlib
|
||||
|
||||
In [22]:
|
||||
|
||||
```
|
||||
```py
|
||||
a = 12
|
||||
a
|
||||
|
||||
@@ -348,20 +348,20 @@ a
|
||||
|
||||
Out[22]:
|
||||
|
||||
```
|
||||
```py
|
||||
12
|
||||
```
|
||||
|
||||
In [23]:
|
||||
|
||||
```
|
||||
```py
|
||||
_ + 13
|
||||
|
||||
```
|
||||
|
||||
Out[23]:
|
||||
|
||||
```
|
||||
```py
|
||||
25
|
||||
```
|
||||
|
||||
@@ -369,12 +369,12 @@ Out[23]:
|
||||
|
||||
In [24]:
|
||||
|
||||
```
|
||||
```py
|
||||
!ping baidu.com
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
正在 Ping baidu.com [180.149.132.47] 具有 32 字节的数据:
|
||||
来自 180.149.132.47 的回复: 字节=32 时间=69ms TTL=49
|
||||
来自 180.149.132.47 的回复: 字节=32 时间=64ms TTL=49
|
||||
@@ -392,12 +392,12 @@ In [24]:
|
||||
|
||||
In [25]:
|
||||
|
||||
```
|
||||
```py
|
||||
1 + "hello"
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
---------------------------------------------------------------------------
|
||||
TypeError Traceback (most recent call last)
|
||||
<ipython-input-25-d37bedb9732a> in <module>()
|
||||
|
||||
Reference in New Issue
Block a user