catalog

. Python语言简介
. Python模块
. 嵌入式Python解析引擎: C++调用Python
. Python 调用 C (base)
. 扩展Python语法解析器功能: Python中调用C++
. Python 调用 C++ (Boost.Python)
. python 调用 c++ (ctypes)
. 脚本语言扩展性

1. Python语言简介

Python是一门简单易学且功能强大的编程语言。它拥有高效的高级数据结构,并且能够用简单而又高效的方式进行面向对象编程。Python优雅的语法和动态类型,再结合它的解释性,使其在大多数平台的许多领域成为编写脚本或开发应用程序的理想语言

. 我们可以自由地从 Python官方点: http://www.python.org,以源代码或二进制形式获取 Python 解释器及其标准扩展库,并可以自由的分发。此站点同时也提供了大量的第三方 Python 模块、程序和工具,及其附加文档
. 我们可以很容易的使用 C 或 C++(其他可以通过 C 调用的语言)为 Python 解释器扩展新函数和数据类型。Python 还可以被用作定制应用程序的一门扩展语言,这点和Lua是一致的

0x1: 使用 Python 解释器

. Python 解释器通常被安装在目标机器的 /usr/local/bin/pythonXXX 目录下。将 /usr/local/bin 目录包含进 Unix shell 的搜索路径里,以确保可以通过输入: pythonXX 命令来启动,进入交互模式
. 第二种启动 Python 解释器的方法是 python -c command [arg] ...,这种方法可以在 命令行 执行 Python 语句,类似于 shell 中的 -c 选项。由于 Python 语句通常会包含空格或其他特殊 shell 字符,一般建议将 命令 用单引号包裹起来
. 有一些 Python 模块也可以当作脚本使用。你可以使用 python -m module [arg] ... 命令调用它们,这类似在命令行中键入完整的路径名执行 模块 源文件一样
. 使用脚本文件时,经常会运行脚本然后进入交互模式。这也可以通过在脚本之前加上 -i 参数来实现

1. 参数传递

. 调用解释器时,脚本名和附加参数传入一个名为 sys.argv 的字符串列表。你能够获取这个列表通过执行 import sys,列表的长度大于等于1
. 没有给定脚本和参数时,它至少也有一个元素:sys.argv[] 此时为空字符串
) 脚本名指定为 '-' (表示标准输入)时,sys.argv[] 被设定为 '-'
) 使用 -c 指令 时,sys.argv[] 被设定为 '-c'
) 使用 -m 模块参数时,sys.argv[] 被设定为指定模块的全名
) -c 指令 或者 -m 模块 之后的参数不会被 Python 解释器的选项处理机制所截获,而是留在 sys.argv 中,供脚本命令操作

2. 交互模式

. 从 tty 读取命令时,我们称解释器工作于 交互模式。这种模式下它根据主提示符来执行,主提示符通常标识为三个大于号(>>>)
. 继续的部分被称为 从属提示符,由三个点标识(...)。在第一行之前,解释器打印欢迎信息、版本号和授权提示

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfIAAACWCAIAAACq4Z1/AAATdUlEQVR4nO2dW7plMBBGjcuAjMdoTMZg9INNbn9FBfty9FpfP5y2I1VJKFHk13UAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE9jnJdlWZZlGr7tCQDAw1kD7lvDbT/Oq4H9j/yHjWFaAuGXffM89mXhZKOfbff3XmmMFrXuX+w5TPPYj/MbnR8mLsMAf5ObQ4MKNeO8Rd6jQDRMr5J92KcLsX+YlnncSm4xZ5hOBJ9wQdlNXke1TraolbLe1dSdY6cHjrAO8AdJT911cjiPQzqJ77ckSjw1LjcmU9Ow92qiT6usTZb7cd7Cd8owldujsB48Cn7qFkWtftXZj/OyzPOcNzNuZeL4PCatMNp+1CIX58L6OC/LPO5+hUvj3pb9b3vgpvKWqBh3q+sA4DuUoWGYtpPzNdUcpiWabodJcrnRnvStca34VQYma16b790X1549dKZhtGhRYnf/W98BDMMQquyzXZK/7XuRCzP13FwXHlQcpnbiPEoYr/j+JPytB67sED3uF2+eAOBOVFhPY1D6/9fpLzd21bA+DZ6wbiUr+nFe5IR3iyN9Fu0WFbyU3SisR3P8zVZcragxrtoI6870y2poGroyNBpjpO5dslJxPXE+aN0cO3yQhNlsGeMuuw4AvsOHwrqRdclLG8mKYVp0TI8rsbPk1bAewpCITfGNSFLLK2Im/suw7k2/rBW+OilzVyXKHJP1LMJG/q8XmsRfwjrAYzgO6+mJGp/IopIQxcJ9eWW2WqQXQsn9p5AKiF2KE/rBoo5xZVjvx2nPJExxQCrDekg0L3lEm9J6j9p++gmkGqPtBqjGejUsW7f+Z0zir3a+vPjpcSesA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vehHddm60adDRXoruvOh3XTJWbrAM8kTcIs0xDPoI9mnUYMiGtIw3pSVcXQG8J6cVOSehMsXgnrVp3uCqyu606HddullrB+d6YLAN5Hctav/8mibwUrMOwzu7SqvGLb0H8a1u2u674d1gHgzxCf9duddsMdd5wqeN3tR4Ehe3+iiFSmIRXWX/uOc3NuvZNhPb08hEpCOihkbjSipFGnXUEe1o2us2pzJWEMlwjrAA8ke+y3RBNi33PDNGsQJppbGmHe9Nn77GlcdCnIDaVO7SFp2zyP4/YANXPfvMfYjE9D+lqgnSw6TD+ZJStZFGPXpJmi63QzvW03XJLWjZ7ffiHcAwAAAAAAAAAAAAAAAHhY1D8AAHgn/wCmFSSMJcQauAAAAABJRU5ErkJggg==" alt="" />

3. 源程序编码

默认情况下,Python 源文件是 UTF-8 编码。在此编码下,全世界大多数语言的字符可以同时用在字符串、标识符和注释中 — 尽管 Python 标准库仅使用 ASCII 字符做为标识符,这只是任何可移植代码应该遵守的约定。如果要正确的显示所有的字符,你的编辑器必须能识别出文件是 UTF-8 编码,并且它使用的字体能支持文件中所有的字符
我们也可以为源文件指定不同的字符编码。为此,在 #! 行(首行)后插入至少一行特殊的注释行来定义源文件的编码

# -*- coding: encoding -*-
# -*- coding: cp- -*-

0x2: Python语法

1. 数字

. 解释器表现得就像一个简单的计算器:可以向其录入一些表达式,它会给出返回值。表达式语法很直白:运算符 +,-,* 和 / 与其它语言一样(例如:Pascal 或 C);括号 (()) 用于分组
. 整数(例如,, , )的类型是 int,带有小数部分的数字(例如,5.0, 1.6)的类型是 float
. 除法(/)永远返回一个浮点数。如要使用 floor 除法 并且得到整数结果(丢掉任何小数部分),你可以使用 // 运算符;要计算余数你可以使用 %
. 可以使用 ** 运算符计算幂乘方
. 号( '=' )用于给变量赋值。赋值之后,在下一个提示符之前不会有任何结果显示
. 变量在使用前必须 “定义”(赋值),否则会出错
. 浮点数有完整的支持;整数和浮点数的混合计算中,整数会被转换为浮点数
. 交互模式中,最近一个表达式的值赋给变量 _。这样我们就可以把它当作一个桌面计算器,很方便的用于连续计算,此变量对于用户是只读的。不要尝试给它赋值 —— 你只会创建一个独立的同名局部变量,它屏蔽了系统内置变量的魔术效果
. 除了 int 和 float,Python 还支持其它数字类型,例如 Decimal 和 Fraction。Python 还内建支持 复数 ,使用后缀 j 或 J 表示虚数部分(例如,+5j)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARIAAAFiCAIAAAC1d8C1AAATDUlEQVR4nO3d7bWqyhKFYeIyIMbY2RjCiYJkCMbzQ4H+qIaa0LBofZ9xf+zLcQEiUxC6qO6///779+9fB8CP2AAyYgPIiA0guyQ2/fB6G5+PO88T8Ili83iO+V7on1jwHF9D33Vd1/XDa3w6Xv95ecV5AjWlR5vHc3y9Xsl+65+4oR8qxUadJ1CTeZLWD8bJj39iycMXCCk2znkCNRV/29Q+7LxP69ZeMf9aeXl/tWzPEzhDITb9YOy0/onG7Pz7t/P4Ic0TqCmPTfVfN89R+wnkvCQg/qwC6smupGVf4f6JpvcrF55IeE74tHkCNXG7E5ARG0BGbAAZsQFkxAaQERtARmwAGbEBZGZsHtyEB1ZYsemH8cnAYqDIHJM29GrRC/BLjDK18dnJtWLAL0li0w+fKgBiAxQlsYmGFlPNAphKF6A52gBF9pU0jjbACm53AjJiA8iIDSAjNoCM2AAyYgPIiA0gIzaA7ILYhA8DDJ97O91VrTYcobSgUleC6eV0yIHogv42j+eYv/Qxd6iZR48eZi6o7/s5Nn2/JFR4A0Digv425t4cjHmr1qDGjk3Qx2D5r/Wyil90QX+b8Nxpzko4VLTWsFFzQeZaPp7DMIw8QBo7Xdbfpuu6ruuH6XXe2KRPSXceJJYFzaeD4aGoH+Y1Dl4JOF3T32Y2J+SMkzRzQaZwpTlfg+z8/jbBLjpVXHdd93gO88Shzm5rL8gWvKAfONpAdHp/my480Qq+182JBynzXF5LaqDidicgIzaAjNgAMmIDyIgNICM2gIzYADJiA8iy2MwjhqM7htVrY4CG5c+A/iSjH17LQJj6tTFAw8on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N3xM/vb6a8eUb72naSZl+ByVgnQ9PecpP2s0/vb2K1sCo9xWh4h9Xzv1dPLhj5+aFTQ3mYYx3hNXDu0LzWlEiBS8+Nav29jcezSRy+gk5rf9o2xcdzuPLjbc7vzx31lbD4KXWs4TOCob44NcBJiA8iIDSAjNoCM2ACym/W3AVpwq/42QBvu2t8GuLF79rcBbu2G/W2Au7tbfxugAbfqbwO04Ub9bYBWcLsTkBEbQEZsABmxAWSnx+Zl/Q9oGrEBVP8DtdWSkX/HB2IAAAAASUVORK5CYII=" alt="" />

2. 字符串

相比数值,Python 也提供了可以通过几种不同方式表示的字符串。它们可以用单引号 ('...') 或双引号 ("...") 标识。\ 可以用来转义引号

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADACAIAAADZSyttAAAIfklEQVR4nO2d4ZGkKhRGiasDsmqyMYSNwmQIxv3R2oJcFPUCiufUq3pTrq3YfosIZ+6af//+/f39GYArECNQgBiBAmVi9OntOI5Dl/s85Wjvii7hxejT29H2H3+P9I0bdENrX3p7V3SFdW8k/i1L3xgjjN334+M4joO1Q2dMb8fR9t0wb+2CHW1vjJlu4LxTb8dxM9DLx93d5mPYvl/iIG4M2hm9ojcjPtS6Qbg36RslusFPXDfMn+oG7zZOe3XD77Bd99306e206dPbcUqe7T/OsQI+vZ3C5/w8f9zM2Y1ulNspX9GriY6NMnVLP7w+5bfJOcp8A53uZFxiNHTGmOl/8Ri5n/0dYP70vIftnUN6GyPthIBIjJzO4MzGIyz3rBt+N8/M4XA6iSUuyTES/+hYjIR2QkAYo9zdkDHG63jcGDkPyCkAzu1dBiPpMRIfPU4gvqeMbpTbCQHBm9oyLDi88QDOo2L0epvlKeQ86qYHkv2mdtpg+880iNl+aZJO5Yybh18XKG0U2wkBd5p+9B9qZfAeZpsbYYP7xGjpCwrcwaWXEWYB0t49weE+MYIHQ4xAAWIEChAjUIAYgQLECBRInMV+NO1d0e0QeqP2TJr2ruhuCDHCDYKjSGMj3CA4SNIQGzc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zcoB7nqG+EGmbu6QTk4HSPcoN1jei2/jxuUg/rTj7hBDVA/Rud44PihZZ4aI7gVxAgUyB6jUfoP2uI/f25f7u8lbXQAAAAASUVORK5CYII=" alt="" />

在交互式解释器中,输出的字符串会用引号引起来,特殊字符会用反斜杠转义。虽然可能和输入看上去不太一样,但是两个字符串是相等的

. 如果字符串中只有单引号而没有双引号,就用双引号引用
. 否则用单引号引用
. print() 函数生成可读性更好的输出, 它会省去引号并且打印出转义后的特殊字符

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAACFCAIAAAA7GrHuAAAICUlEQVR4nO2dWZK0KhBGXVctyIjejathMyzGfnBgSgQtsdQ8J+7D/W2ELOVjkEzo/v7+usfRm9H0vzYCXsEjBQBwFggAVIMAQDUIAFSDAEA1CABUcy8BfAb79QfOz2Dt8AmyHINMlyu98f4w2NFhhwNF5v4Slb4r19TOSo7c8w35F1djifCUeuO/xIY4AXwGOyaF1l+8ks9gs480WSNI30BvxtH0XW/G+Gds5LtNdmUiLX3L+PRe2c4aDv+W0ylbIqjkqrWeoAcQ26v6iwmDHUc79GZuWJfk0wU79FOzO19ekrlMP4MdR2vt0ix/gnRjnHz5q2BqWH+WBjttteJX9Vk7BmOt6XMmdflOICp92/j03oydUimBndNvMSa20yUsakrK013zfmz64oJfavqyAKQmtTeXtLLpEKg3wtOpvyhk5mq4S+zuDTu76GHNjWAX1ux8Iyo9tR1tSVK6rzpPqKlJ2U47Kb2+B6hGtHOwiZ2+SvPDto08u75flbDVeXojorrBmPSOrukD5DnAaV1Bto7kxnjZKtj1xn95mRK/nEPE+XoN9voH2aRNqwIaCEC00ytmtvMTTHRKjZeUp5/DhgDCn3i0Ivdm92TsAJIAxM6n/mKYwP8NjxPAitdeZgVQOXNrIQA/88WkVAAHZ5Zrnv5MN8nqJQI4exYQTOD8h/atAOb/97vn+d/fDBzD0r03VyeAqnedMf6L7zaynYIAdtRFKU+vXqdj9ngIFPywaF5XZ8TVQ6DJtOiN1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qSivB7LsvJV6eBfvuP564B2Df/bIx7Lv/YgGw734pT/bdf1U4VDIHYN/9zTw79t1/156M5Ukw++57ecbp2Xf/6VQLQIB999l3//E0FgD77ruMde27/xRKAmDfffbdz7+fF8BCWMy75nhQAAGAahAAqAYBgGoQAKgGAYBqEACoBgGAau4lgDP81z+iu6aP8sV/8Hnk+QBbrkQ161isdcFC0/MBBjuOdvDc2qfLcuRArf/6djhBVLczpxPs2dQXXk3j8wF8V/ag1qWRAxNl//VuqweIanb2dAL6AJhofD7ApnelpJwK78VtB9UxEZDUVfSmbnNfeDuNzwcI3eivF8BKFOuEAGCi/fkAo1jpvxVAJpwgVGT+dAKGQDDR/HwAOzgHeBftGnuv7/Nf3wgnCGr2VjQC9R+6rvk6wEnbqOwqkc+gUE9TAbhvkBdWNxbCYAf3WgkGuBgEAKpBAKAaBACqQQCgGgQAqvEEoOMoAACf2B3aX0Z96VEAAA5JAG8/CgBgRQiIkfx8XnYUAMBMsQeYeNtRAAAT+TlAwPuOAgDoujMF8LSjAAC63GdQHUcBALAQBrpBAKAaBACqQQCgGgQAqkEAoBoEAKpBAKAa2RlutLa0t8gp+Hvn5hNIaQgSgFPwBeA21LnwBIAaVyGCBKAVsgA8Mn72zr/BGOPJJkiZ8913d5v+gAAIEoDTyA2BXJ2W/Ozd+MP1Fd6+tN74RPbdDw7FONgDECQAJ5A/H8D0OT970Wk09A5dk4i++3tPqiBIAFqR+wo01yfRz/4hAiBIAMoE26N7gwRXgaUK6s8WlqFPEEe21k6hXvoKqIoRIEgAmhGfD5AOF0Q/ez+xdG26Pee770ceWLtx1ABBAtAYFsJANQgAVIMAQDUIAFTTVgCj9B/AfUAAoJl/UqobdqgYVOgAAAAASUVORK5CYII=" alt="" />

如果你前面带有 \ 的字符被当作特殊字符,你可以使用 原始字符串,方法是在第一个引号前面加上一个 r

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMUAAABWCAIAAADwqMVKAAAEDklEQVR4nO2dbXKDIBCGcy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O93QWjVB8aKqDwfFu0P8u4whguKdEBTvDvHvSpYB9Z591VZQvDvEvytaVlZ89lVLQfHuEP+ucAzrPfuqoaB4Px7/TjeUoeKzr5oJikf8uzZMtRIUj/h3kOXo+0yAg6AnsAQ9gSXoCSxBT2AJegJLao9/x2EbbVF//Dv+s70lGoh/d+UeIDhIE/HvLtwDBMdoI/7dd/cAQTmtxL/75h4gKKeZ+Hdf3AME5TQU/+5be4DgDVqKf4dbqR/ej4Ml6AksQU9gyel6mrQv+FXQExjyD07NpBccywMFAAAAAElFTkSuQmCC" alt="" />

字符串文本能够分成多行。一种方法是使用三引号:"""...""" 或者 '''...'''。行尾换行符会被自动包含到字符串中,但是可以在行尾加上 \ 来避免这个行为。下面的示例: 可以使用反斜杠为行结尾的连续字符串,它表示下一行在逻辑上是本行的后续内容:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbwAAACHCAIAAADiGHtSAAANx0lEQVR4nO2d27WrIBRFrcuCHON0Ywm3CpuhGO9HlOfCQHwE45xf5xCFTdSVjcKy+/fv39/fXwcAACUgmgAAFSCaAAAVIJoAABUgmgAAFSCaAAAVNCea/Wjmadhdhxl7V988T8MwzbOtuLSwH40Z98UCAL9FIJr9aGarNl114ZX0o8lK6zD5sjtM8zwN3TDNXsTFhWFdAPB44kxzTbeCjcoLE0Yzz2YcpvnFuvmrwIzDaLzidTNXaT+aeTbGvMpXKbPVxZuvn/ola7YYZLD1hQAAXZcZng/TPCeJZHmhqMypYpjYvf4dJr+KKIdc8r8uVMN8phm0cQRhdADwbLL3NA9LOePBsjfy1WKUiGawh2s00+IB90Qjtm4FAMDDyIimTNfKC8MN/OHtHUWTZBMALKloHn1XM3qu4g/P94nm8rcbvtv2jlc4ngcBwIvk6fk8R889ygs1w2TG0YQPbXpXkH++Y8bebrg81E6fJen7rCcInDeLCQAezPnzNMPh+RWco5okmwDQnS+aNqW8UnB60kIAOInmVgQBALQMogkAUAGiCQBQAaIJAFABogkAUAGiCQBQwVVT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uVmauulM0RfCaN1fHqV63SjTf7y579BVP3mNBNKFNsm9XEq6jid/rYpQqxtrx7tIZ1u1WYK66y+9VBq+xQ1jvHS1ned2KPqaiqXfPHY5L4ryGdkQz45IJj0Q/YBGWqRm71mEyoxvVbe2unWFfFJqrfuz3mvWa3WzGe0JyltetbNiM/aLXw0b7mcNxRZxX0Y5oAhzHMSOV35w5dFuv21ZANOH3cMnKhxddtbnqDbix121jIJoAABUgmgAAFSCaAAAVIJoAABUgmgAAFSCaAAAVNCSa7n2zb948i/Pm71N8MgBcTUOi6S93ezevde+012bnzcJK+cmg+e4hvvUJVh78rbv5MfcVTeG86fvzbbj7qSV6rwVixsS7J5Z/ld6C8Cn6ZLjFIc6YbOrg31Rhpmly30O4u+zR+24GrScN5YI/pZv3pDHRLDta2q/Qs030DFS0kZ8S5cCM0a2PzVr+lXgLwseok+E+h1i0roOXuI97u/w913fRI1GYCV41tDPTrOjmXWnKT/Oj4fm6yji0snEVyBVx+ooKbHHSSN0VVe4tCJ8iToYbHeK09VzwJfvmd5c9Sgt18Lkg9ohmeTfvS2OZ5gmi6Rf5P7YlV5Q0W/zMWxAqqRBNv6iRQ9yYaOrgEc3P+B3RDI1t3Ekl/QqVB6K+oqTlX6m3IHyOOhnuc4hF6zJ4jffeDTvc1buXimYmeNWQ/urO6OZdaUc01xGEm2WS+2HPOW+KcVb+NmnkgZi27r/GanaWf1XegvAhuZPhRoc4aj0T/Jv+++2ku8se5bqpg1cNyeBP6eZNaUc0AQBuAKIJAFABogkAUAGiCQBQAaIJAFABogkAUAGiCQBQAaIJAFABogkAUM5/3m3pDEk0OLoAAAAASUVORK5CYII=" alt="" />

字符串可以由 + 操作符连接(粘到一起),可以由 * 表示重复:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALEAAAAoCAIAAAA+IowZAAACF0lEQVR4nO2a4c2DIBCGncuBLnEbRnAKlmEYvh+C4nnogWLly/ukSRN60AMfkVKGeZ6naRoAWIETgAMnAAdOAA6cABw4AThwAnDgBODACcB5xwmy3nvvvTOjItYZTZujcd57S5Up3axe0OZo3I3vaZHnBTsnRuOOl01fmIFs7BPZ884R0eoE0dUwkL01WCXVjdMF3kzptTbP4fOEqKW+8JxLJ8J0optS9l5uQ7e04kzM0TknNVmitdaJQ5uxR1t1Kc+k35aM26dakucziM8OssJF0RcKLAJpDNK2OBwVS67c9gDKz1JXhsotl6UkVhfyjM+XcP3JJiNQkOczZNcTLSaMy95tQ1NzZ2ScWJvSrlQ20olLvSA6TSyT5xjKwtvOidfJOEFW6L6+MIv6hqvheSeElh+o3p8TT08QiTRkfe1V0bDOLsZ5/2knDnl+14kxrG92EfrCHGExUT31qtl+8pplJRe/2ZKw2iug1gn27EnujV2e1saPgyXv/9ZIwZ4V4MAJwIETgAMnAAdOAA6cABw4AThwAnCU+5g/prsjCF0jzBO/3URrwf/rUVMEJ2rPJbSIHAZhU7qDIwhdI60n6s8ltIg8xGeqf+oIQtdo1pj6/6BbRB7iM9U/9ddi18AJwNE5oT2X0CIyxnd1BKFrVPsT+nMJz0f2eQSha7BnBThwAnDgBODACcBp7oSXXuDLwAnAgROA8Qf3/bDeTSoBAwAAAABJRU5ErkJggg==" alt="" />

相邻的两个字符串文本自动连接在一起

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIQAAAAkCAIAAADHOgUeAAAB10lEQVRoge2Z3dGsIAyGty4KYma7SQlbRZpJMXwXKqLE3aByzsuYZ/Zijfwoj8BoXp/P5/1+vxwEXAYQLgMIlwGEywDCZQDhMoD4NzICSUqJYw5ETgXFCVv1SyUjGxu755Ia2MgIJEko1N3agl+oByCQLMeRf92Vffy+dpRRQq3conTHfmaoxu3BI2p55RhFFgrzbBGaIut/tbqxo+0MzFdLwjyfKQpPd1QEA0lKIlKVbLokO+oyFbnquyWoUT39hYz8d5KyVCib/T15LB1lSBYxa/HI+UYCSRGtSrZekpnDPaPTFNnVWp65NTi1o43gSX4sU5GXuVjK156PpWQ/DmQUj8mZoIGD4SYRCne6GFtG7ymxVlZrRhaiO287kMytrUuOImM71rnA/5Mxje6uS3uwgWJj1Rb0e3fG3NnU7HwotJ7h+NovnKGIcNyW7AXgS9+NS9RgIMn4Nl0eAZKMx+MygHAZQLgMIFwGEC4DCMMbeFvuYQdu8gAQZWZcyT0MlDwARJFxOvcwVvIAEG3PuJB7GCh5AIhpA7fnHgb6Xg2IVYYx9+AyrnBFhpJ7GCh5AIhBRlvuYZjkASAXX/qem3vowVkZj8899MA/hwDhMoDoLiNpP0fjD5BbxdnUaLTwAAAAAElFTkSuQmCC" alt="" />

它只用于两个字符串文本,不能用于字符串表达式

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANYAAAC0CAIAAABnvUUoAAALsUlEQVR4nO2dW7akIAxFa1w1INe6s3EIPQonw2DsD0sNIYEghVHr7NUfdWkfPI6gEg+vf//+/f39vQDwAhIEzkCCwBlIEDgDCQJnIEHgzD0k+B7D/CGMb5I4DWednJxpmGZCKQvJ7iAmkuB7DKSJqxO78R6DZxMOE9cQydAwleSV7g4ovBcUr1l7YsIY5jmMW79BGm6e5zAOS/f2SRY7uz1tnucw0v2lvmkayK/vkF5v9JoYpjC+twLRwqm7A4o4EA9TJILaROFgnwYbJrLxvu/Siu8x0Gbbfuu9IEte2vpV6pnekagtak2ORzK0/VwKse5A66TcUf406r3g17rDuAFI48TtlCojuuuzSHA/SO8Wp3mll81yXuf7hruhSDDqruoT4w1If5aRYPL3jl2CwzSHUHhKqe8FrRkaw6c3hwIrSCX47bvBYSIdmj5avTIDllGCw/TJzfajF1qGhimMY3TJgSLJEzEZWWoTZYYpjHu/sw1V4ogbve5Yb7HiwTndbjnAesj9caTbIwA5eyJEPHpU0/+94PBTvQIG4Wp6S3Dr7p7eMrmuEeS4x+wIeDCQIHAGEgTOQILAGUgQOAMJAmfuIcEO8YKWqZ2vhFkhXrDA78YLZqMAN75wZsQL5vndeEF2FbE5v3XnMUzTxLNEMvpJfI9hnkMIyZbpiQDjB+MFScbUK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Eo+hYFDL5FNgjUrAn+2Fx8y9rIrpoOyE6G0bnI5n6xQvRsuX4Nl7K+mH/+W5KlcveEMEhRvdMH1uUnDYYIOOAMJAme6S3CW/gGwAQkCX/4DtWKwhJMVOtwAAAAASUVORK5CYII=" alt="" />

如果你想连接多个变量或者连接一个变量和一个字符串文本,使用 +,这个功能在你想切分很长的字符串的时候特别有用

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfMAAABlCAIAAADWJZ32AAANEElEQVR4nO2d27WjMAxFUxcFsdZ042poxsVkPgL4IckWIQ/iu/eajwwXsCybgzFwuP379+8GAAAjgbIDAIwGyg4AMBooOwDAaKDsAACj8QPKPoV4X4lhyhYu86cKb5c0L91VXlMQAICLpOxTiJlyHl74NqYQ36F33r1K2dYCekGMLzk/AADcqjG7Om70LxSEeL/HMC/riHtb/bEghvkxGF8Xq0PztOx+v8eQb18Uvy5a5uxXLzafilansb0yZQghLstSB59VaV04hXi/xxjFmrIgAICnkbMx8yJE58hCZWer/M1LtnLadl5imG5TiJtwF7/tMXu1+CGMjz17NNs9yhb708fsWzXT6ll9s7mjeZFrGgUBADyHPs/+ssF7qVYPEa9/pt0U4/NsRt2j7GknjklxvSQnndmYeXmclsoa7htVOThWNACAB03Zi8H18YXlCrl42cou/p/wK/u83GP03lh9fmYcZQeAi1Mp+6tn2uclGxTnWieU3JyLcCr7PsuRpjuanFL2VZFTUYqyl8K9r4CyA8DbKZ+NSXcpDy/UmZcY0kTLQ9ym6rZoMfVerlpOnWR6Wu1g22W6g9qdYznzNMsewaOUvcjq5m5e0ceaMk6m1gHg9bz5eXaGpQAAH+etyr6PWRmYAgB8jh94BxUAAA6BsgMAjAbKDgAwGig7AMBooOwAAKOBsgMAjEbvHdTytaCDTy9iXA4A8AXqMXvTjrzjRohxOQDAFaiVXbqET5UnyrT7qz+WrL8xLgcAuAhinr1lR64ZFma/MS4HALgC/Tuopa9VWrjbe+2qi70tAMAVcCm7NmIOcTVZTH9E2QEArsDTyv4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QHFpIRbrafU9XdiN1/qPDF6c7dSeVvZkQR69rhVRWyMDZRt1js7NPf1esalrstX+ZKOkpu3EJqt7xy9b237tJezUWK4mQa5ZXONVdift2C2ZtP+/laiugYmO9dKWgbcVlt6Gvw1+WrPn10iXT9gnZbBLWrGYV/LzZ4d+KkA4Er6cuhpQU2T325jAaTta+UbqvRmpG/V3xQHMoPaQ5MahsKILXevK+Re/ocMfpTt2+4rSO7foT23WoWkKO9DqtmrlaxXzQ6ai7EZJ6bPY7zuGuaB0Ib1N2+CxPzGhdkfaIHv4mP94rfuvYRNkvQTqHv26i7XukUc7vHAjwLiZ58fZT/OixibIDAIwGyg4AMBrvVfa79g8AAN7K25W9uwQAAF4Lyg4AMBooOwDAYPwHS7wf64HusmYAAAAASUVORK5CYII=" alt="" />

字符串也可以被截取(检索)。类似于 C ,字符串的第一个字符索引为 0 。Python没有单独的字符类型;一个字符就是一个简单的长度为1的字符串(和PHP类似)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABRCAIAAADXfUqBAAADT0lEQVR4nO2dW5arIBBFGRcDYq3MhtEwmRqM/eGDV6HEYCdFnb3uR0Si6AZE6Loxr9fLAFVAuTqgXB1Qrg4pyl1YliW4QUeznvLDubAkvHmeIWWrivQYUbn1tJC3dUH6Ep/H07gbUluy8fAunN56yxRkQNnGVuoTslbO1rT+xJK16eyVY/3K+p3tc7L3yOySbCZpfsGNVF7X2lSkC+TtUaK0dEV3cBTTUwihuCLmMq2nZSGiKidbpIeoO3YXqtK8k1jkyHZvmy5k9SCKjAdccyZ7z9tAvLe9nXPVkhPlx8e0+PEz38r3M8YD85fpQp2zUaSH4J/lo5r7end2XYfxtB7UrYvd9fgdSWvN2rLTEqRFuejYXdg7BvYyk+Q95z/DKU+q553EPAN56yl4T0fP/IDy91s5dwjuK5627ibunEz54Ke5MS4EIvLW+EB09G3Jpab3r1BeVIdnBzcN5cYF8j5zYz1tm7FMjPLGZf6S8tVhUYj+xAbroMRsN8qmB6gHNmVi9vIUiHpP+j7peZjndNGVHbnX9G2TfNxTDFL3nHvK/rS70Rt9jpT38i8y8k3hF4DyNmdNXzBQrg4oVweUqwPK1QHl6oBydUhRXi+r5CtuR548bUua6R3rY+SulxebcbGqnLadbi7lQ+Sul7c3y7lrKM+Qu15+UgPOK4d25K6XQ/lN5K6Xo2O/idz18mr4Fo6HRcDw7QS56+WlSGZI2MipHCnv5TX9IqE8Q7LyjkkWTMXUyFUObgLl6oBydUC5OqBcHVCujqvZt2bg9f/FQ4OxlK28P/D63+KhwVhK5T2B162cQATVs7wr8JrPCURwPXxjA6+BXLqUozHPBJSr40r5pNGXmsFUjDqgXB1Qrg4oVweUqwPK1QHl6oBydUhRfhlfzoRDGPxRM8dM8eWtMmHGOGOa+HIo72Wa+PK0Yy8MQ3nGNPHlCf05VTJNfLlp74LyjFniy/OHBf5LgRMQX64OKe/lNYgvv4lk5Ygvv4Vc5eAmUK4OKFcHlKsDytUB5eromX1jQXy5VK7jy1sgvlwo5/HlP/F722Asl/Hl3/+9bTCWy+Hb93+JF4wFytUB5eo4V/4Tv7cNxoKpGHVAuTqgXB1Qro5nlS/cP/BV/gBGlVyHZWpVGAAAAABJRU5ErkJggg==" alt="" />

除了索引,还支持 切片。索引用于获得单个字符,切片 让你获得一个子字符串

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIIAAABFCAIAAAAJjKmmAAACrElEQVR4nO2cW7aDIAxFGRcDYjwZTSaTwXA/qDzCQ/RqxdWzVz80RcQkQgmkxgAAAAAAAAD+iWPvPbtMQuKVyLH3WtavzHvvhayS7V57N5Ykb9ZR4f2QKDMUp5bko0PH48bFgsaxFxrc4iEsSe0Q80JNcLBNJzZz389x7o9bYVd6eXRcdmMzZKeOM+UOW1qUrOt8Esfl23pQqEoUX39OHRe2SU+eKgwlbeG4VafUPc2PB2awldYXMoMx170W4UE3FUYr5Laxyo2tvtrEL0+ZYfSI5asweeHXyLz1jLAsIGRJmEhir3K7GXRX02qWr21Q1/kYF48OxjhmESFriEViB5OpIH9yPbiWJhp3SpY4dnRcmlm1k6Tb7gXMENqrfGReOKhVKBxEHacROo4tuagauMMYLVLcVKusMewnsR4rEiPTgn3uUBnMcJh6+vYvVpm+AQAAAACAIdWcM5s/Tfycm5xagz3qSGYWUdBhnZnLwRnqJZ069rYtDQRJOm5eDk5ReXxmhniYx+DKeNz+CwNOUcbhkjBou146AbfQUXQImMIK36KnacdCtLvAAi4hD/hrY2A4XgJ0SM8yekUAAAAAAAD4RSbyG1pZCy0am9XMOhtkXp7fMMhaUOT7B8e3eIg35zcU9x3mNyxvBmPMa/MbIioU2TRDLwiwkBmMeWV+Q2rOgaDvVJ1P8cr8BtPPWhgw3dF9l/fmN/SyFlp7TbIucbnct1fnN/SzFhru0smE0HWCGZDfsATIbwAAAAAA+EVm5sZHN88j6eE4w/yGyLFpDpIeDqOWdMpkn6hLEmau4gG9IAGSHo4zym+IpDhaKt5dRUDSwxXsdEpbuLQfvgZXADMsQQrKp5B/6z+kuqsI4BrUzpPPqZD6y832xhMAAAAArIdvfcC3qZUOM3T4A20GXHjDrri2AAAAAElFTkSuQmCC" alt="" />

注意,包含起始的字符,不包含末尾的字符。这使得 s[:i] + s[i:] 永远等于 s

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMwAAABFCAIAAACJ/561AAADs0lEQVR4nO2c65WDIBCFqYuCOCfdUEKqoJkphv2hKE+ddR113Pud/ZEgIVy8PCLsmO/3+/l8DABywGRAHJgMiAOTAXFgMiAOTAbEgcmAODAZEEeRyVyIMQaXpXiKddLoczHGSN5WaXsfvQOGzJ6icVn3yyxMZj219eYnyuOpav395vOU2tiFSH6jNP73SrMtc0MRp7QbqEcy66m1Pj+xZupKyY4265Pz67w7psyu7LpLvw1u12SblXJBymRXy+wqGml/nsmMMbPeeqDiJ1Y5isvzWxeKW7K2wlrglNMW/baZR35hMtvkPnMku1ZmV5Eykxlz3pA2tURquaXx81uSN1Z1s8p2dIHX+n01zczCsU4sGfany2V2FXV5rMmyLngkscxA3noK3tMyEVxrMhdi936cuia7VOZI0dHKC9Oa7ORVmTEuBCLy1vhASW+xmMhboWr96s4cmC49Dat47sL/MpkjRUqmy6maVRfhJw5YBnbraWnadUG8zEF5UrNOnpbERMWX7pusLJO51mnh5LxI5liREpNp44/Nd3/r81AvU7nJmtGJyUOeUvJQL1O1yYAOYDIgDkwGxIHJgDgwGRAHJgPiMJ74lxt4v/w53G73HoC5tQAeSmcka32RbXrU+2oV7VGHUx4GnmJVcBcdk7UHEtut3XQmakqZX1dnFtJHPIUQmkMMzUEr6ylGImpydqsEFNFbkzWjVWay5WW+xbu+7o9kyXBrwf2DVuvWcF2FnQEUPBrWwr/c5l0Tp/ueG2tnukynEgZnYLLk+hQrUAzXZL1xZDptUFyEyUDLX0xmXCDvCzdYT/PbderrmGxw0AomeycMk+UnnTrrrWpBXv271vyW/Hql+geLlDOlpFPM+D35Gv74MPb+s0rg+Rw12dbwBkABtpWAODAZEAcmA+LAZEAcmAyIA5MBcRSZ7Gh8MmPmJ73tGbknPn1hyqwVjcu6X+br45MZY+b9ryaz0vhkxpiRIk5pN/Af4pNNW6+SJrtBZqtIWZiCV8UnS3v2siPZlTIHipSZzJj3xCdbCjxiskfGJ9tQ1OWxJntPfLIqhk556cQ12XUyNxQdrbwwr49PtpFZaXyyUbqS6fJ98clMWYZk9OsrZXYVKTGZNtQH7uKhXqZyk8Vu393nIU8peaiXqdpkQAcwGRAHJgPiwGRAHJgMiAOTAXEQnwyIg/hkQBzEJwPiID4ZEAfxyYA4iE8GxEF8MiAO4pMBcRCfDIiD+GRAHGwrAXFgMiCOuMli7w/8J34Af785fY9/j4IAAAAASUVORK5CYII=" alt="" />

切片的索引有非常有用的默认值;省略的第一个索引默认为零,省略的第二个索引默认为切片的字符串的大小(include to the end)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGoAAABiCAIAAAA3ENGtAAACwUlEQVR4nO2c3ZWDIBCFrYuCqGeqoZkphn0wwjCAoKhZw/3OPphZfm8gypybLAsAAID/hnXee2dFhNjrUK2e994zGRVrVT2GIZZ9HA3eD7GSrz1/4k0k6zzTTmtXYIjzd6U/qFnf5U1oI5bL51ouiq2wTVdVWD3ONuXbHZR1t8v36Sdd6geDqkTy789L6xJN4zRig2tJk6yebPMekM9kpe+SrzqQE8twHfU29aCe1FROTKmdztm6lnx7s0mX3qHqRxGr40wwLcBkiB0Rh933rHzW+Vy7/urHuPjTb1msc8xMZiHHHDaimI+chpJPSXti8xJXh3i1fGvn6o3qD+60yrReBG3inSN8dspQdkNZ7x3MSadt+dI2m+rPxeD8Id/ZZ99bHpsBAAAA8DjZg7t4bu2413ceRX6XPLMhTk762NlTfS7yVGh+pt9Sc2skXherT0a2woR84VKe7dNzfnuBTkZ6vo/BVaU8DwkSKgKtCRSo16KmkHVM5PrSVtMiE25axNlvE4Ng455jb0kCAAAAAMxOp7/P7PgK0rbg78vnbx1T58M8/H0Fk4azOl4bKfx9WV6SKY8/LV+1z//t7wt1v7d5w0he6O9TDq3mJOHvK3f+pc37fn9fLC6KfeOz7w3A3zcE/H0AAADA7Awa9ODvGzPowd9X8PcVzlfMrM5XleqToRIb5dxcPL/rPAj8fZJKckmE9be0gQDyjVHOzUG+XvLc3BbZ0vBz32sBAAAAAAD4P1z5+317BYdSnW/39+VVqr/f19PFQV7u72sM5hnnxlv9fbuo7zXebHx5nb9P/9qXbqfT0HSJfK/09+1MplO7/jar/IC/b0nKlId4w+b9BX9faUaRWB6mv1umOpV8l+a5YfoDAAAAXgf8fWPA3zcE/H1jwN93ITCoDQH5xoC/bwz4+wAAADyJL/2BXnKxflS+P5HgLVsPEBgfAAAAAElFTkSuQmCC" alt="" />

Python字符串不可以被更改 — 它们是 不可变的。因此,赋值给字符串索引的位置会导致错误

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZ4AAABFCAIAAAD1kBcAAAAJ50lEQVR4nO2dW7KkIBBEXZcLMmJ242rYDItxPmywoLKk8NE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0HMleNhm47R735XCjFSHkgVDaCCEP5F5pW9A/Qgi5m9ulrZlCCCGXQ2kjhDwQShsh5Hn8B5+8xf/1+cujAAAAAElFTkSuQmCC" alt="" />

如果你需要一个不同的字符串,你应该创建一个新的

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM4AAABFCAIAAACNCk6IAAAEHElEQVR4nO2c65WDIBCFqcuCPCfdUEKqoJkphv1hQB4DDj5mjbnf2R8JQcVwMwjcHfN+v1+vlwHgaiA1oASkBpSA1IASkBpQAlIDSuhIbbLkvXczUxj4fMjWvAOzK9u1ND8pmp2XtX2peMe7vJJMapMlT3bKa8gLO9QdlXyUnahTs8KSam8Vl6veejcPNEm58f9PGdU68UdS2KIjzUJqIyLe6q0leoSzTUkYWiNqvFaoPOfR6hOBvHdzX2qtwtb39PNSM8Z8vt6yv+WFHLNrqbKQWqdmxXZvVSGT7GTM7DL9rSdZb2epmXzKDaCQ2gjNZ7WLwls8JNYvpSYgRhpfhib+QkEmUWlp/U5bpkwO5W9AKLUWkNpC8rvfU7jFQakFBL01O7KTJWctxREQUvsXaqldGs4Cq0CzAWwQSW/NzhGRnYx1RHEwJMuepJR9LkMMoIeoZqDeJ90wVjhEfDA/8IVLemuZZiwvoo7SdZZPYb70UkwWloYSZbdcz0DrtRsDqUWwhLubg1qB1ICUaglXDJZwAbgQSA0oAakBJSA1oASkBpSA1IASQ7sF9frkJiOeoCa3NbGBAZioJveW1UzMwuQJa5WnCBb8L4zUJN6yYO7KXheGiyANS865yoFROcYmS94TEefVGHVighvCPauJvGVpgFtf81EtyG49Me8YW3e0yyYMmNjATdmeFrRMNrE8rbAxgAZLRcPGUyh53x2Bm7JfasYsVolMXZAaaCFY7Gh7y2ZH1maamCx93q6DISO1hmMMUnsyonW1tresflyPc4Ol/POW7PpJ8X8koWYoCQZtzDkfxsEl3J8zXYHd7JVa6k6F2IAAbEwBJSA1oASkBpSA1IASkBpQAlIDSnyR1AQZztrHFW6Ra/497qCv7uG2PKX8aichSTtVHZK5STpnk1+3yUFf3bNteRfnV9POcNZtVLmver7U8l+gJe/JJs1Pbqew+nGHP43L86vpZjjrSK02nVyQNajw1aVNXm+Zt/oxhz+Ly/OrqWc4a7WiTmYjyQTocwZjTt7geG+s1e/xXJ9fTTvDGdcCPmnS9bnQ8iE7uTfG6vd4FPKraWY4q5u02s0rNKSWPYpmU+DS6vd4FPKrqWU4M7XU8nNKcvGxHIlqawvyczx6CsDxRetqNbfPcNbzEv/U4GnM10tt7zqsSoazGM/yy/yq1e+rpQa+CUgNKAGpASUgNaAEpAaUgNSAEoLdgnwj8Lz5+cPtWaBAlF8t2R0603vwbHsWKBDlV6v3wznTFexZoIcov1oiNS5rUHwNexZoM5YepohJpekK9izQRio1TiKV6Qr2LNDmiNQq0xXsWaCNLJVfc6Ujf7CHPQu0OTW/GuxZoM2J+dVgzwI9sDEFlIDUgBKXS81zf+AH0ZDaZgn4BSA1oMMfSosI6h1kmssAAAAASUVORK5CYII=" alt="" />

3. 列表(list)

Python 有几个 复合 数据类型,用于表示其它的值。最通用的是 list (列表) ,它可以写作中括号之间的一列逗号分隔的值。列表的元素不必是同一类型(这点和Lua是类似的)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOsAAAA0CAIAAADkAFh4AAADQUlEQVR4nO2c0Y3sIAxFqYuCkKYbSpgqaIZi8j4SwIB54xCSGWvv0X6smGCb5GIIQZj3+/16vQwASoGCgW6gYKAbKBjoBgoGuoGCgW6g4Gl83LZtCy4XuNAUnMf6OG1hj2e2+jD4ZDZ6O2ezqmuTuar0uHAq8krB1sc+UHnhH8PH6o77uAXXFp7EhejnLFgfj+fhwoQSRsFfecy7zSOk6Ns4meuvK9ikPtKYkheylH4XYo4y9c/orY/bFr0Lydz+E2lz7rPJYrrCVXmQ9G9yl1jvK2Dv+BUFWx+n+4ALpcnTMbQVqdFLuPCcgg+HzKghL+yspQtcONRmS/+k/YC0obTZOJcFSj0V17sD62OuQv5nvHPQ0S0J/sP9XKzgFPOCHDybNxvX1ocQLk1Ncmy5Or3Pjc2VCi6uliTjPB1KV9kq2DLssQrmZ05dgugkSIUr1OQ51io4N2fWQpl0xmGa+0DjuoyKc1MTY0yab3K/tDbXKtgFph/LCwfk1OiCVMEkWzeabYe4j0MeTdLcj9/NwZX/cZwyU2tmEfTRzk0o9vFA6G6ZglfPhElXyxqylVbJLCLnodRycmXzVtHdUzZPcN4XIVQwyWQzZs9W5+Za0upt8NVkrPwktMktq5BO0T2OFQreJdk8ZnkhDxnFSYvo2M693vnmvW4fHY8y2yQsO3bFe19CvxYxbKjUcWl/VSKozr3vnqg+CJ6+Bp8UcDuokTzSPbcUw9p58INcW4H6GqKwLy47frf6YzaNMVoVTNa8vxbDLN0XDY75V6AfqP6kzekx8hdyMADzQMFAN1Aw0A0UDHQDBQPdQMFAN1Aw0A32BwPdYH8w0A32BwPdYH8w0A32BwPdYH8w0A32BwPd/MJ6sNL9weAnwP5goJtfyMEAzAMFA91AwUA3UDDQDRQMdAMFA92wCsbJuDKbVd31J+MCCQMFt6fRBJyM29k8QrrvXFEgQaLg/xQKwcm4UPBdPKFgnIwLBd/HAwrGybhQ8I08oGCcjAsF38gVBeNkXMINJ+MCCcK1iOEWX5yMe9/JuECCPAe34GRcMVDwjci+aHDgZFyhTXzRuBV8VQa6gYKBbm5X8Mb9AbCKJxT8sQSAWf4BnMNnoI6kz2YAAAAASUVORK5CYII=" alt="" />

声明时使用[]和list()是等效的,同时就像字符串(以及其它所有内建的 序列 类型)一样,列表可以被索引和切片:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJMAAABfCAIAAABjrWKNAAAD2UlEQVR4nO2d27WrIBRFqcuCGCPdWEKqoBmK4Xz4YAMbD5qHrLDm17kG5YYpyGsb83w+H4+HIXDQHCo0h8rI5mYfQgjOxiPWhZAdWw/JVH2QmJtmH/w8pSnaD6Ix+8THNPtVkHXZd8tSdkFe56bZl3dY+0GVJWUIITi/F8F2e/t5mn0IfrZuu9zykZ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xfoOa0/nExr2PbQYcx1xDl+8Twf4fuuY4I3ECAM2B8geZSFz/PCYJGwAAAABJRU5ErkJggg==" alt="" />

所有的切片操作都会返回一个包含请求的元素的新列表。这意味着下面的切片操作返回列表一个新的(浅)拷贝副本

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJIAAAAjCAIAAADwj8QJAAAChklEQVRoge1aW7LDIAh1XS7Ime7G1bgZFsP9MCoabIjmUb2e6UdrFAxHqILq8/moheGwaBsSi7YhsWgbEou2IfFvabOAiOjM107GoaDXC0i0aQsIVueP5Y2jwYKUDHnP55B5m7awX1vyRha+JyKig/j+2ypGsNoCIljjgjj/CGw5OrSkHiZzmNSTLilWu1KKI6P2Tj9Pm1Jqs0rpTPLGnbTQwbjNJtpCMA41FLGOcZEkYyIrVFNS7RVoC3EI+c5oD5iNNqUudbvgWLGXzsxg3FfaiA9hTlu2XGi3rO9Oe8REQXKDcYwPyRsriE5gnJQ24pcFUQVtu9917QFT0Xb1v1tiJRlOZwSRILlZ3v/bFT2LXdCOJqLou/aAWYKkn3X+bicaeZAgRSxCQxe3T7HFBgURAYJN84CY2GNU8do9ZqHtJbxllKmC5KNIriRx3Isxy3F7YSAs2obEom1ILNqGxKJtSCzahsSett3O2O+CuzbB2kKzhHC6bhtenXwQ21CBIgeXMJbPnd53fuBoKzLl6EznkdM4sG0SUuKfzV4doTb5noJhypMaRwtMNYG3nNYPaevX7TOLbRJo7rF5DuXAw7yzFFmlYi7aQg73Am9r9ZBCtbbOua7IG+cWh9Mg2VwhOoG7aYsru1UCTSZfQ1uqpLdFXqVUuJjBPSllDklbka5vktE/h5K2yH9bvPSeL1T3W7SRNStCfcmLwF1KaE3hZ7cW0iOhTG5TTFZCRz32BCQ7yWrJTDqfVEnLWgTDuStAJ4ZXJk9vBp1krbz+QMqwu/1/mMN73lai887du8Mfk6mUepA2WSGq7yD35vAnZT523F4YAIu2IXEvbch9FvpxO22HLQvn8QfAr1rCcNQawQAAAABJRU5ErkJggg==" alt="" />

列表也支持连接这样的操作:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAS4AAAAiCAIAAABul6PbAAAEFElEQVR4nO2c3ZXjIAyFqYuCOGe6oYSpgmYohn1wAAEiBuRxyPp+Zx8yxEgK5iL8o1W/v78/Pz8KAPBZIEUAtgBSBGALIEUAtgBSXMb6EEJwJrcYF0IIIXirmSPb9kG09aWfZLBonIINqXU0TP7pTeNykHz36KloZxpfTetDdDeFFLX17XQZb/wvsH705FVHGhfPu3F0AohHyjhvqS9t/ctg6WicTki1o5kQX4Hk2JSyPjgzMZ5tkG13fbS+gtVvGqORL5Wiei2M9Qkeb2TRcQkOzqehIRnE+hC8NS6aO76K62vunVfceIQpMlM+ks401nufZSlmqEKayTGLtr6akdTkylTrhNQ6WjGpawNCMVTdyZ/GxfnANl7i/VbYDapxzG5qvLGxFg9IiSOvY4oKmh9TY5LSqKfs+nCgrU9dyGfG+1tEUtT1plVb55xgNxl/SDcrzmdcPiTO0Vyc7SKo1LrBTnf6Z/rMNl7i/Va614oXpseYANNR5dKZkwgrRZLrQinF9jqHQhVYeD8Nkp9TDSNZMaf6pd1k+o2lrxSr935aimxIHUejaOtiGHHhjECKo3SkaBwzFccbO6RkZdyoFEn+rMRX77NOt4I0bfa5YINKvqKjs7BXLZYXLviFqcaGdOroLE5y4rBBXaOV4tVXiyQbJDHoYvTIBpXMjObI6mZDM7PZtMN5f8uqFMkMNy7wW2V6vTe3Y2Wj4nbsAzY7IbGOBm0SO+dSnPrtzW2bmH5JImYbe973pbmD2iyK4408xc6vEGB7NyXfy7HVTZxjN/Zq09UirvuueO9vWM+KneslcttoTYn1cwLuPtacTS4kxtGETe4qoLxiKM/8gE2+OzvIf3aleis7PFf8pvEirIf9F4+CnmyzzzdNrQ9LMae86euTj9M+4h9l9XkgbM45Wj0/n2GHrAgAgBQB2ANIEYAtgBQB2AJIEYAtgBQB2AJWis1temHhmVKiWjhheV43eEEZIXkIE/v23pWdN4pyR9q4HOS3lTt2pFifOScoPFNKSWrhhOV5veAlT5rze7HkHbfqNbRZUO6oyjF8XLnjiBTfNA5yTS2cIIa6o7iMkBo6PgmlSE2i3DHxoLfJ75CirBZOWJ530L5VLCojJLGl7nSDumgT5Y5PLne8QYrCWjhhed5Bv+Bg/UWs421K7hvZy10odyRAildKUVgLd1EMtRQlZYQqZpRBd7Og3FES4Zvu/+0GVVh0N9t9sTyPcy0sI+TuFJIpWhZGjtlEuSNv8kHljoN3UAlk1CbGZL0WTlie1wleUEZY/9cdsQN/wTM8Sih3LE0+rtxxPCvWCAvPPtsdNmFzgB2k2Cx5LcLCs892h03YPHU0IIIrwYtvAGwBpAjAFvy5FAP3DwBQcYcUT1sAeDz/AMGNl+C95n05AAAAAElFTkSuQmCC" alt="" />

不像 不可变的 字符串,列表是 可变的,它允许修改元素

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOkAAABECAIAAADr14WEAAAEzElEQVR4nO2dXXaEIAyFXZcL8pzuhtWwGRdjH3QkQGDCX2vwfqcPLR1CwAsiRGb5+flZANAItAu0Au0CrUC7QCvQLtDKQ7Rr9uPYzX97sZj9OI7DbnfCZoOEMs7s1VX7ZD92swYpR4tfZzVvs+vnb1pSuZ+BN7HziYKuD5ZXxml3NXvsuTyxlc0+QrteC5r9sFuYKGez1wVZzV7RXmfpl6GrcUgrrZV+xRevzr3AT7bploU6nyuopjLeuHv2i8CIPJHH9T9rrVnPv+12/4dclbtf3oZJTyW1dql2rxUWC9uCDdr9+FyrM2opSKo06XzyTLUPRWl3nPMjtXsVxdw65ImRTx8hktGaOHpX7DL2+X0361XX64Pkd9f+m810IHqHEt5k+2qXeNCkDVamdV6txlqbGSDqp0cpf6jzmYL6aNcV0j4AJwaHhHa9eeZu1kh8VLKtbc3SV7ursfc8dav18+zyTGqVU+6mFzS4+39lZVmHeOe5gnpp9zPsVSYS2rTL3uBC++lZ8r+Pu141q6XGVvBry6QNkuc+xkaPyrqyMg+p0fy4WbvdZ7x0hnM33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AAAABJRU5ErkJggg==" alt="" />

还可以使用 append() 方法在列表的末尾添加新的元素

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOQAAABDCAIAAAADLD6MAAAFWUlEQVR4nO2dUZKsIAxFXRcLourthtWwGRbj+9DGkARFtHsM3lPzMRMFIlwjamSmf//+TQCYAGIFZoBYgRkeItaQ5jmFv/biBnyc5zn60uhCSsEVu8zzPBPbauQFp6Vn6M4+0mLvYhOrC2kW/dBuvIqPQ4h1mqaQmOZ8JCoM6fOHj/n8XIyi4KR1dFHbuygiqwtJnt7tRp0tkMQYgyOxZ9myDpiPKbhPGMkVZ0sRhzZrTGKApZuklTWEZ5+WwqpRbd2FNM8pJeESKcw1V1UXPz9lQTUk+Hh/qLCBnAb4yK5Q54yMLZCQeExGJQ/YWtnn9xTcevlcdyS/b4Po48EZ431unJYpgpurGKutf/bMKnRFuGQu1bTlRCBlBhdijPzsLdp9G/qc9a4QKwdkmqaqWMmuPqbgSGDj87Zs2h81WgMpzBs61TqJd6vz5VFyKW1CZo6JaQ/rLKJ77t4Y8/vTaGJVY0G7kXBNrMc3EzT4qVtznTQa0yJZrNJYvQpfFauP+t2kFGvRkis21A56ZJhYb5+10vvg3PvZSB4CLCPoylLqBY8YS7Fyl4iIyJ1K0dBHBDWjcnxSrIVaxcyEndAhVXuNn9nF3GPndHgN5dMAcca3G2vQq2kxosuVNcT1pmSeUyC3Q47tScorJtoUtWw3dylv8pE0tE01FaPS1Odoos/byL3i8ndij+GotvjcYt1QWovTTR7na7X6lOesP0R9RvbVB2f3quu9Wn2dWLVQpRtvpHwpcA28FADAABArMAPECswAsQIzQKzADBArMMNDxPqafNbiNUPDo7JLT4W3dy/kVa3hJ1/IZ72d3XxWcpiVxImtmPd5/0/2mG7Ui8vsMPGHMZDPWjOqrd+Yz3qk1SIIk3QExXiAkrNlM7gin/Wv8lmPtEp75Xy/Z7flbMNubEU+65/ksx7H1Wk7B4qXtapxH+aR3QxD5LP+Pp+V1fIDuINjiBX5rKXx/nxWUcmXIM0ydY4wDUA+6w/yWbPpB7HNKd2pu2OFhzxn/SHW81kv8ihnTvI2sZrPZ73IIC8FAHg4ECswA8QKzACxAjNArMAMECsww0PEOkw+K/giyGcFZhg7nxUMxeD5rGAkxs5nBUMxcj4rGIyR8lnB4IyUzwoG5yHPWQE4BmIFZoBYgRkgVmAGiBWYAWIFZoBYgRkgVmAGKVaxltfyEL776fv2AuBScX0hvX6/Pi8gihe6buf//zX5KRe75K1oy291NMRKV8dIPcyTLfGyspfUhWDvf2mjiVVZqqlpyTsNutJeR4cVy/ORZMJ1c8vyZpVqNWeWdVl6alR7SXP+6hoCap21MbqSd1xZ3nWSvVTfs182OodivdjqlovSKyxaEzN1VlnJj1lqu+Jlvezm/H0LXvAOkevC3tNQKcG9XrIu1tqKSx3VSA/6vHIhxsizvHNOzDfESp1XcyU6kB3CDPphnm2Dla71kroQrDmxuhDzXHN3VfH9SpIy5e0N1WS93y0U5DB0u1h158vWz6LWKf8DfPXyfApS+qCXrEfWInW1W1vqYPde5mgSLul9ctPWm3Yoe6nqfGX/Fmp1SrHKw+wj13zYS2LW/gyxqv+WREIUWoi1sfjO3bkcgMY6yy9kDq5crXVqZTXniYTKZNzrHaJcmrXDbGuovrwrb2tvz1+Ltfy0pMxIbfFE/wSlrTj/roUWkPdbJ3RFvjjUn8CcrVPppZrz+iT+UodUxkg9zOZeqt5siF6q35b8TWTlXPwa+xsfc1up8yUNTdP0E7GKiCO5uCTtN1a0tVLnexpq0NE58LoVmAFiBWb4rlhn7QeAPr4u1kMLAI1ArMAMECuwwn92wNa2h75SdwAAAABJRU5ErkJggg==" alt="" />

也可以对切片赋值,此操作可以改变列表的尺寸,或清空它

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWsAAADBCAIAAACG1AYTAAAM7ElEQVR4nO3d65GzOgyAYeqiIOqhGppxMdkfhOCLbAssh7C8z5yZsx8LKLBYMReLYQAAAAAAbKbl9Xq9Xq9luvqT2JpdvF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hIfQroCDu0bspvsYwHKMhYY6DyYRxzCvQkHh+TI7Rpmh+PF124/N5aAzrIFBAjqGAHEMBOYaCe3M8pH4Bl7s9x4ePAOeRYwj4D5xqlsAyN/25AAAAAElFTkSuQmCC" alt="" />

. 第一行包括了一个 多重赋值:变量 a 和 b 同时获得了新的值  和  最后一行又使用了一次,这点和Lua是类似的
. 变量赋值前,右边首先完成计算。右边的表达式从左到右计算。
条件(这里是 b < )为 true 时, while 循环执行。在 Python 中,类似于 C,任何非零整数都是 true; 是 false 条件也可以是字符串或列表,实际上可以是任何序列

0x3: Python流程控制

1. IF语句

>>> x = int(input("Please enter an integer: "))
Please enter an integer:
>>> if x < :
... x =
... print('Negative changed to zero')
... elif x == :
... print('Zero')
... elif x == :
... print('Single')
... else:
... print('More')
...
More

2. FOR语句

Python 中的 for 语句和 C 或 Pascal 中的略有不同。通常的循环可能会依据一个等差数值步进过程(如 Pascal),或由用户来定义迭代步骤和中止条件(如 C ),Python 的 for 语句依据任意序列(链表或字符串)中的子项,按它们在序列中的顺序来进行迭代,相当于PHP中的foreach

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUgAAABzCAIAAAB1vAy+AAAIrElEQVR4nO2dW5qsKgxGHZcDcjyOhskwGPvBUgMkXBStS6/1nYezbYSABJDiN8MAAAAAAAAAAP+HyS3L4qabS5n9EhUzzr57wRfzbLh9nH1LOacb+b4aVZm03r8sy7L4eTxpxCehNMjklrhvNmSWNEv9xfuZ/QOOnRRxZUQZDZMvjlJ3DnInG/nOGhVNspq5MxeLabrdaJCzFqgjZ/1F1bp9CBjFdHgMsfsAsSWewlnzNVAti5uOWh23O9/1mSoNp4xiu03eObf+SVYoTrXZn82zheB2s5G38o+Cx9kvi/c+mdsKjbymtJ9m5xqZJqkT83FNNH6a0qq7PtmnHUx/mnqnre8M5lLDaM9LQ8vkkmJaLkYpgj+//jm5oH8cth4ZrinFX+UQduQ6uczoMgbPPPEuDa3hJhfedtgkW3+a9mtBr9FLjP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qoFsqK4P/TudBIqSu39ZTyfLrwQs1ZJre55X5bZRxvu0bX51LLsWMrmLOhF0XZpqq7HIOpOZ51ZYZWSlXgqecpRSTycy26Y8fDVGUc70yNrqPauitepPUoSaEP5xw7s9OTzkLGl4kSgWdx9yiaVGscuz6O9517V6mtk1sUH8axoRfl9zpLUG0MCInL6CkVx9ZTiov6ajkIxK049va3UhzvtnVw04Zaunlm/urAUhz6UNGZVEF1uAW1e3uwmE3vX4KVfKzcLuYpLY1/MhqjnbsxTlaM420WZTRJhROGC/xte2JJLm6Z4tfQC7pTO5f3yTV4ENCVr9Rjv5c7fJADKgAAAABwmkX7DwC+m9SNcWyArwfHBngTf109oCXx+7jEAAAAAElFTkSuQmCC" alt="" />

在迭代过程中修改迭代序列不安全(只有在使用链表这样的可变序列时才会有这样的情况)。如果你想要修改你迭代的序列(例如,复制选择项),你可以迭代它的复本。使用切割标识就可以很方便的做到这一点

>>> for w in words[:]:  # Loop over a slice copy of the entire list.
... if len(w) > :
... words.insert(, w)
...
>>> words
['defenestrate', 'cat', 'window', 'defenestrate']

3. range()函数

如果你需要一个数值序列,内置函数 range() 会很方便,它生成一个等差级数链表:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAACGCAIAAAD7HTfDAAAEcElEQVR4nO3dXZKjIBiFYdblgqjq3bAaNsNinAui8vMdQ7qNic771FzMGIdoPAIKie7n58cBJsIBiXBAIhyQCAckwgHpjHBMIc0PKUzHlRn9sWt+gSmk9SMqPrbic/PxsM/wqS0cU0j9sRtfqE0hXebgfJiPRY7LoKh13quqOXJWm7ceX2gp0j/PKVT/vTolfMz/9PmlvaLzqiNv3685hTTPKaWRiszepHLbn5S5vH0KIS4F7FWj9XEX4XA+Gts9fEBe0TcrPhrbPb6w19Ucxd7Vdf5W4EDlOV4fNWv6uHyKAyehsUnerympot2UWexaSEuSppDKM2T9+1JIuddls9LuQLfZJ4VDvtVvq5A2HPWBL199qT39QziKY1ofnl6/SWZXoC+z2uslB1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XBAIhyQCAek94Zjtv7gKt4ejqdL8LUIByTCAeUfZ5FkG2BbOccAAAAASUVORK5CYII=" alt="" />

可以指定一个不同的步进值(甚至是负数,有时这也被称为 "步长"),同时指定range的重复次数

range(, )
through range(, , )
, , , range(-, -, -)
-, -, -

需要迭代链表索引的话,如下所示结合使 用 range() 和 len()

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVcAAACWCAIAAADlkFzqAAALbUlEQVR4nO2d25WsOAxFiYuAvNbNhhAmCifjYGo+KMAP2QgwdNPa+2OmLm38qMIHPyR5+O+///79+zcUTMG78ioA/D0kFXD+8/l8Pp8w/UydAOBJamMBALACKgBgHVQAwDqoAIB1UAEA66ACANZBBQCsgwoAWOfVKjCFz+fziY0cxylEV5xPbZ+m0M0UKi3o6u3On8ksu6tvlbqkVN6+mKkVWY5TOFtONU9dlQ5xoEUKGk+pUM9vSdcsfRMVGKfwCdNYlqy7+DiCmXPWM5wPYUkUf77OuY5bv/2cyXZyV+8qdUh55HbVNzBKqcSL+jzrVdJypUVidrV3VeeCFvKxgKiK+osSc8I7TJKFxmfy5Hzwfk41hfWjWKVZVMPkohHGcm3IPpcFHaW4fQrer5bbY5Sq/OqWF83Hu+Qb6F2l6g/Xu6CZ7NcUXqdrw+O/iBcreW4tyirwSIuK7zOqup8fuzkT58O0Ji6y2C/oMOKM4DuSHk9ezHFuruI4hUbS6BeSf9ESqfHOp89NmMYpeLf9p1WlrTnORz9InFmloMPkt08heqy3qUJRz2iQXLwYOlep/sP1LmgYhsqjnF+8MhYYpxCLeCJtj7So/mt+O/f3CYtnss5/9p+6W1RgqV+fQUHcvfvOIvYbP3+tS3dZn5ZaldJ+vtR+vedON8so921AWNZzzOcAN9bpvh9O5G4VKF4zt7epPhL5bCrwHah+x56LCuRvskMFHaaiApkCHb0YES/wNNvTaSyQ1+77SnduWL/zepXECs7CfbMISCog1fM5FVD/cL24fSzwSCuqpYvf569Vgc4rA9Ev1H1FUa8CSV3qVZK/cOfDNF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tzMkagDAw+jjC3z/cE4FCkNDOZSAlHIgagDArei9iQbdKeEVCl0pQwnUUlauAUAf9J7F80u6V7llKIEW+AsD3IdSBZzfceY7hhRKoAUqAHAfmhnBFh2sSHbStVgMJdCAGQHAfeyvDo5peIEe8QWGSiiBRmJEAOAu3hBfABEAuJMXxBfAagjgVrAgBrAOKgBgHVQAwDqoAIB1UAEA66ACANZR7hS64nzhQ5RRA5LTSPKkJ3cgq3nqqsSWJBhFYzW0nQx22kagYmeo8lEUPRnr7o1av0cCGQDMHIsvcLqbVAwNsx4rvMyj88m2v4gXK3lGBtBpBQhkADCjjS/w7UynX5Wyfojv7fzilbHAOIXVGTH+XKsSowEwiD6+wDD07yR3q0DuCbX7pseFGQxyTAX0s24dt48Fji74oQJgEMWMIPpX2kkuuRYPw6BXgW+h2zKlfFG4/eDohRkBGES1OhiHCs12Dy9u6iXZiheT1NLmZSxR0u3J5Z3qIgJgkTfEF3gMRABM8oL4Ao+B1RDYBAtiAOugAgDWQQUArIMKAFgHFQCwDioAYB39TuFYO6JIwYH4AgqmUD0ujagBAIdRWw05H6ZLRxafji8gZlez9idqAMBRlPEFZued8yqgiy8QWyov9dhsf6cQ2RqHaU1cZEHUAIAjqOILLK47FxwKdfEFnIt8hcbvp49366Gm3+G984lSZO4FRA0AOILGs3idWfd1Ky4zjMMBbCrg3ZZyU4Ej7sP4CwM00KhAEqqja3fK4wKtxa4dGxUAuBttxLFhGOQwgf3iC0SBQ7bJfVUFthru+j0xIwBooY4+usUiT670jC8QhQwI84bf98J3KTBMcVABMeZBrTBEAKCKgfgCiABAk78fXwCrIYA2WBADWAcVADDO/9Xy6YubR5bZAAAAAElFTkSuQmCC" alt="" />

4. break 和 continue 语句, 以及循环中的 else 子句

break 语句和 C 中的类似,用于跳出最近的一级 for 或 while 循环

5. pass 语句

pass 语句什么也不做。它用于那些语法上必须要有什么语句,但程序什么也不做的场合

>>> while True:
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
...

0x4: 定义函数

def fib(n):    # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = ,
while a < n:
print a,
a, b = b, a+b
print # Now call the function we just defined:
fib()

关于Python中的函数,需要明白以下几点

. 关键字 def 引入了一个函数 定义。在其后必须跟有函数名和包括形式参数的圆括号。函数体语句从下一行开始,必须是缩进的
. 函数体的第一行语句可以是可选的字符串文本,这个字符串是函数的文档字符串,或者称为 docstring
. 函数 调用 会为函数局部变量生成一个新的符号表。确切的说,所有函数中的变量赋值都是将值存储在局部符号表。变量引用首先在局部符号表中查找,然后是包含函数的局部符号表,然后是全局符号表,最后是内置名字表。因此,全局变量不能在函数中直接赋值(除非用 global 语句命名),尽管他们可以被引用
//这点和PHP是类似的 . 函数引用的实际参数在函数调用时引入局部符号表,因此,实参总是 传值调用(这里的 值 总是一个对象 引用 ,而不是该对象的值)(可以理解为指针传递)。一个函数被另一个函数调用时,一个新的局部符号表在调用过程中被创建。
. 一个函数定义会在当前符号表内引入函数名。函数名指代的值(即函数体)有一个被 Python 解释器认定为 用户自定义函数 的类型。 这个值可以赋予其他的名字(即变量名),然后它也可以被当做函数使用。这可以作为通用的重命名机制

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYkAAAC3CAIAAABouDWDAAAM4UlEQVR4nO3da5KzKhCA4azLBbEeVsNmWIzzQ0Eu3YDxEjN5nzpVZz7HIKB2wNH29QIAAAAAAAAA4LcYN8+zM+2VJuvnlbfT7jUn65NNWD/P3rbL6GzFuM4KVzPO28n6Xr/tkvfSYcbNudjnO3fHHU5u+wM2hFN0z7Hxs3BsTeNaJ4Nx/aNnZJ0LLc08OTZpmznn440+b+8OXOnsL7h/IX6tOhO7Rxz0bMvmzhesuGbYTroH1lFH/Yv1A2HRZP08e++FEZtxwghuKfOGfT0Qm5Z2hzqurXUmLjdxybZ2Vvdi3JP1ydAQNhz3WejZsTu2La0b0nZHumLVA/M8e+dcWFlYKFVJb1HoDt86aIc7WetPaUO1bc4RNvgK49Dk9NKbo+ziu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x67XDKL5VUY+vl+slLumBUSj9fXvpdr1hKl0/T6+6jc5Ct2PTD3pYXTLNSmwPJfOPFYm/tMmUKTQyTqFiq1Pa6nloz655XN6R1fL2PRtueVlaoemx7o8Sqmd1edj6GPKFUcXcIXaf2klRTeevEpttY78w743mge5kSAG6TjNkYOwAAAAAAAAAAAADA/3JFEqKBTDrpndMAULoi681Ymdy5B0AhZr25okzpMYr1iVPu4gMgGBnjVEkkOrFk7KlL47JHn3hsBkDizjldFZvUvB8Aft1Hx03EJgCKj46btolcN58KgN+hJCE6v0whk85yD0GZkR8AAAAAAAAAAAAAAAAAAODh9PxN+csv5dcdiu9pHF3IcyoANPozK8UbpZO3naYvON1ePz7tXchr5gHIWvmb1Lix5YTL3hi/f+GL3CgANNq4SYsa6frpR+PP4wvXzTByAlDTcwYIQWOyPh1enRObyMwLoDYem5acJvk6R+d0xCYAssE5nfVCPrnJunWV7acdC9fNMKcDkGvmb0qjRpn4MvxikvIvjS8kNAHY74a4QWgCsN90daJc7r0EAAAAAODjZuk/APgwYhOAJyI24XuFG5y4aeA/IjbhCkvUuDRmxBwpU/EsTPnv/H7Q7Tft7FFv3oog5pk6ndKiK7ZyrPS1olUhxnnbe/0zsQlXOPmt49JhvN0p1TvI4z1P6d1VYvYo4+aYE+qNs1JJKXWM1DqxRVds6JT9WBeybIrYhHv8AfvMfmIXZrD2AAAAAElFTkSuQmCC" alt="" />

定义一个返回斐波那契数列数字列表的函数,而不是打印它

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAACzCAIAAABw2zNfAAASD0lEQVR4nO2dWbKkIBBFXZcLIqJ3w2rYDIup/lDmRKEcSh/nRH9U85RJzAuomdO/f/8mAAAYEAQAAGBQEAAAgEFBAAAABgUBAAAYFAQAAGBQRAFQ5vP5GLV95qztZ8XqufvIWduoCG0/H6ulk5WpFzJru1O0MjsH7KKM1bO2e73xOHy/ha5f/9La8zeSVukvFATwCmorgF2T124U245URjJD4X5VprBTyuzfzC3Hb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6d1LNWGjRgarlp+cbq2xpj89NY8K5WXTw+pxlqj4vWHyybOOvcp23zLABwl9wUU7srMqYvVcz65zqxAcPoVu0U4tgIQC7rTGTXEtEYjyBZhmXPWhrEkDIXgXS79LSKvAIrx2ZVnWfnK6aFlkR+8jQkKKwD4GakA1Dwqy5OjQgCSM9ZUBOBv0RGNwM0o4vHTOJbKoVB4Ed+csO9sAa3178uzqHz19GgW74tEAOCJJAKQerd/gwCwBXQn7dsT7kmx1tao+PJ9LQB9j3baBKD3cVF++O7p0bIAAYAnkm0BiUb/qAA0+4V/YDQCyGiMRqCMsdbqedLrNrhPbxaAfNj0+FuVRp1kgvt8uBaVF0+PEhMBiGJU7AoAoRTgHrIVQFjU+k3S7SWuS3YH+md9kg/69id3j4hGAAKN0Qh8GM7gcrV5LE3pH4SknfWHcPr6X6vzp86NecqVF0+v5Kj8A2jtHrYRSgF+TXULCECCaAQAf4fkNdCWmRUAAPwNcAUBADAoCAAAwKAgAHA+H+kfADyM/0INo56/RgVgAAAAAElFTkSuQmCC" alt="" />

0x5: 编码风格

. 使用  空格缩进,而非 TAB
. 在小缩进(可以嵌套更深)和大缩进(更易读)之间,4空格是一个很好的折中。TAB 引发了一些混乱,最好弃用折行以确保其不会超过 个字符
.使用空行分隔函数和类,以及函数中的大块代码
. 可能的话,注释独占一行
. 使用文档字符串
. 把空格放到操作符两边,以及逗号后面,但是括号里侧不加空格:a = f(, ) + g(, )
. 统一函数和类命名
. 推荐类名用 驼峰命名, 函数和方法名用 小写_和_下划线。总是用 self 作为方法的第一个参数
. 不要使用花哨的编码,如果你的代码的目的是要在国际化环境。Python 的默认情况下,UTF-,甚至普通的 ASCII 总是工作的最好
. 同样,也不要使用非 ASCII 字符的标识符,除非是不同语种的会阅读或者维护代码

0x6:  数组、多维数组、索引数组

1. 列表(普通一维、多维数组)

list列表是python内置类型,list: 列表(即动态数组,C++标准库的vector,但可含不同类型的元素于一个list中)

a = ["I","you","he","she"]      #元素可为任何类型 

列表可按下标读写,就当作数组处理,以0开始,有负下标的使用

. 0第一个元素
. -1最后一个元素,
. -len第一个元素
. len-1最后一个元素
. 取list的元素数量: len(list) #list的长度。实际该方法是调用了此对象的__len__(self)方法

list的方法

L.append(var)   #追加元素
L.insert(index,var)
L.pop(var) #返回最后一个元素,并从list中删除之
L.remove(var) #删除第一次出现的该元素
L.count(var) #该元素在列表中出现的个数
L.index(var) #该元素的位置,无则抛异常
L.extend(list) #追加list,即合并list到L上
L.sort() #排序
L.reverse() #倒序
list 操作符:,+,*,关键字del
a[:] #片段操作符,用于子list的提取
[,]+[,] #为[,,,]。同extend()
[]* #为[,,,]
del L[] #删除指定下标的元素
del L[:] #删除指定下标范围的元素
list的复制
L1 = L #L1为L的别名,用C来说就是指针地址相同,对L1操作即对L操作。函数参数就是这样传递的
L1 = L[:] #L1为L的克隆,即另一个拷贝 list comprehension
[ <expr1> for k in L if <expr2> ]

list用法

. 创建列表
sample_list = ['a',,('a','b')] . 得到列表中的某一个值
value_start = sample_list[]
end_value = sample_list[-] . 删除列表的第一个值
del sample_list[] . 在列表中插入一个值
sample_list[:] = ['sample value'] . 得到列表的长度
list_length = len(sample_list) . 列表遍历
for element in sample_list:
print element . 产生一个数值递增列表
num_inc_list = range()
#will return a list [,,,...,] . 用某个固定值初始化列表
initial_value =
list_length =
sample_list = [ initial_value for i in range()]
sample_list = [initial_value]*list_length
# sample_list ==[,,,,]

2. dictionary(索引一维、多维数组)

字典(即C++标准库的map)

dict = {'ob1':'computer', 'ob2':'mouse', 'ob3':'printer'}
//每一个元素是pair,包含key、value两部分。key是Integer或string类型,value 是任意类型,键是唯一的,字典只认最后一个赋的键值

dictionary的方法

D.get(key, )       #同dict[key],多了个没有则返回缺省值: 。[]没有则抛异常
D.has_key(key) #有该键返回TRUE,否则FALSE
D.keys() #返回字典键的列表
D.values() #以列表的形式返回字典中的值,返回值的列表中可包含重复元素
D.items() #将所有的字典项以列表方式返回,这些列表中的每一项都来自于(键,值),但是项在返回时并没有特殊的顺序 D.update(dict2) #增加合并字典
D.popitem() #得到一个pair,并从字典中删除它。已空则抛异常
D.clear() #清空字典,同del dict
D.copy() #拷贝字典
D.cmp(dict1,dict2) #比较字典,(优先级为元素个数、键大小、键值大小)
#第一个大返回1,小返回-,一样返回0 dictionary的复制
dict1 = dict #别名
dict2=dict.copy() #克隆,即另一个拷贝

利用dict实现索引数组

def addtwodimdict(thedict, key_a, key_b, val):
if thedict.has_key(key_a):
thedict[key_a][key_b] = val
else:
thedict.update({key_a:{key_b:val}}) addtwodimdict(mapdict, 'Beijing', 'city', 'Beijing')
addtwodimdict(mapdict, 'Chengdu', 'city', 'Chengdu')
addtwodimdict(mapdict, 'Beijing', 'age', )

3. tuple: 元组(常量数组)

tuple = ('a', 'b', 'c', 'd', 'e')
//可以用list的 [],:操作符提取元素。就是不能直接修改元素

4. string: 字符串(即不能修改的字符list) 

str = "Hello My friend"
//字符串是一个整体。如果想直接修改字符串的某一部分,是不可能的。但我们能够读出字符串的某一部分

string的操作

. 子字符串的提取
str[:] . 字符串包含判断操作符:in,not in
"He" in str
"she" not in str . string模块,还提供了很多方法,如
S.find(substring, [start [,end]]) #可指范围查找子串,返回索引值,否则返回-
S.rfind(substring,[start [,end]]) #反向查找
S.index(substring,[start [,end]]) #同find,只是找不到产生ValueError异常
S.rindex(substring,[start [,end]])#同上反向查找
S.count(substring,[start [,end]]) #返回找到子串的个数 S.lowercase()
S.capitalize() #首字母大写
S.lower() #转小写
S.upper() #转大写
S.swapcase() #大小写互换 S.split(str, ' ') #将string转list,以空格切分
S.join(list, ' ') #将list转string,以空格连接 . 处理字符串的内置函数
len(str) #串长度
cmp("my friend", str) #字符串比较。第一个大,返回1
max('abcxyz') #寻找字符串中最大的字符
min('abcxyz') #寻找字符串中最小的字符 . string的转换
float(str) #变成浮点数,float("1e-1") 结果为0.
int(str) #变成整型, int("") 结果为12
int(str,base) #变成base进制整型数,int("",) 结果为2
long(str) #变成长整型,
long(str,base) #变成base进制长整型, . 字符串的格式化(注意其转义字符,和C语言原理类似)
str_format % (参数列表) #参数列表是以tuple的形式定义的,即不可运行中改变
>>>print ""%s's height is %dcm" % ("My brother", 180) #结果显示为 My brother's height is 180cm . list 和 tuple 的相互转化
tuple(ls)
list(ls)

Relevant Link:

http://www.pythondoc.com/pythontutorial3/introduction.html
http://www.pythondoc.com/pythontutorial3/controlflow.html
http://blog.csdn.net/business122/article/details/753699

2. Python模块

如果你退出 Python 解释器并重新进入,你做的任何定义(变量和方法)都会丢失,为了满足这些需要,Python 提供了一个方法可以从文件中获取定义,这样的文件被称为 模块;模块中的定义可以 导入 到另一个模块或 主模块 中
模块是包括 Python 定义和声明的文件。文件名就是模块名加上 .py 后缀。模块的模块名(做为一个字符串)可以由全局变量 __name__ 得到
fibo.py

# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
a, b = ,
while b < n:
print b,
a, b = b, a+b
print def fib2(n): # return Fibonacci series up to n
result = []
a, b = ,
while b < n:
result.append(b)
a, b = b, a+b
return result

可以使用import fibo命令导入这个模块,这样做不会直接把 fibo 中的函数导入当前的语义表;它只是引入了模块名 fibo。你可以通过模块名按如下方式访问这个函数:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVQAAAB0CAIAAABVK11gAAAKKElEQVR4nO2d6a3sKBBGHVcHZOll4xAmCifjYHp+eGErcLF46cs5GmmeuCxl7K/BmKKG//7779+/f0OKcf7uzOOaNC1ewvPkmTTON5geMUnozzxMBcv0aWPqPR0C70IhfgD4iyB+gE5B/ACdgvgBOgXxA3QK4gfolJvE/5mWt31K+hxf4qwvZq6d0/L9LtND9gFcjCP+z7SEn471iY/zmRb1L4wu7zgjfvir+CP/Oh56stAnSux7Uo6szi6XadmG3nWYPf5mKjZD9PFzs+ZaprX0mteq9XT/jBn0v2ZsD+wcVvEf7SdNAvg1xGn/OAuPtT5RxBlo99n1Nn8Y52X6bJVtucZ5q/b4hz8nN01vxduM/G7y1ojSJIBfIvrO33oK4It/Hk2iEb+VZ008hO2U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ejdOup36czC+fiqmu5oqRP3JsQcuR/xhRq6sVr7Ph7TCLIMuC+F8m/nSc9ntsKCt+Gve+st2yK4ofW9DgWbcOMjGej5W3r9UDeXo7mPZr+3qcMyZfxcVjq8W64tGQ7NnF3RD3SuNjMdUruq7yilLHFpTeo1Tc+7Daip6/6nYMpkrn3Qzxx6Kvax/gquJRN3u1fOS37ruKyzHV67quxqRIf1be4lTce3/kr6vzgtthV+llR/wRMk/vpniz4tR5Q53DMPQq/u/5L2nl+hnF20KdzetUiOC3YXsvQKcgfoBOQfwAnYL4AToF8QN0CuIH6JSbxG/tLXE8Kty410SwAriPIGJPsFlCnxhH55BX57ELAFn4I/8FkfpEB499n6W7a32ZjimC+UMLr9jA8GVZpImIY6SzF3SLT+aH9iL6Bvws4rR/i1//KUwM0cfP/PouHK4vR6MdV/LJM7uXp3Hw2Fvc5jmrk6rtUuK6lwD8EtF3/qZTgNtCdCtxonLv6hXOh9vb2/43zsv08V1jGPzhR4mIX4xJrU/0+QHx29OK48+S+Im0B3+EUPwXvPVnTPsPXe1Tb2cV0M6vbz1EFv9el1nMFMV/iR8JwO0Eq/3B9zZ9ooy1bCaupe0z5/VTX7i4FzutuVj8e4Xz6C472oc5fb/fedwStlXIZTJu4475/BDAb8ImH4BOQfwAnfJHxB8swSdoP03Pab112wCl/BHxA0AuiB+gUxA/QKcgfoBOQfwAnaLc4XeFQ37NFj0AqEUY+aXwJ5c45GfFrAKAtgjiDw7quMoh/7JAKwBwjvTOLziuXOOQj4cMwHMoF/ze5pMLALUgfoBOaS3+DId8AHgShfivcsgHgCdhkw9ApyB+gE5B/ACdgvgBOuVy8X+l/wDgaf4HDw8YimT6yvkAAAAASUVORK5CYII=" alt="" />

如果打算频繁使用一个函数,你可以将它赋予一个本地变量

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR8AAAA1CAIAAAD3dXj+AAAD30lEQVR4nO2dW5asIAxFHZcDcjyOxsk4GO+HL8AgB8FH3d579UcVCyGJCSCS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RJcu0pmagpUSHaVaMA1SzUri81tMyGthYNnTtNIltznUfCK4/F91PB/ttJrhD0WmNivEZyS9prO5en4/bY3EjiJq6vaMd6S9UcjJbTOwrORefXrxiZqm8IJGMbcpVPPEyIYw8iYcAAAAAAAA/KdM1h8AVOAYS0QXQB2ILvjz/ANbMTUn6bB38gAAAABJRU5ErkJggg==" alt="" />

. 除了包含函数定义外,模块也可以包含可执行语句。这些语句一般用来初始化模块。他们仅在 第一次 被导入的地方执行一次
. 每个模块都有自己私有的符号表(符号表是模块独立的),被模块内所有的函数定义作为全局符号表使用。因此,模块的作者可以在模块内部使用全局变量,而无需担心它与某个用户的全局变量意外冲突
. 模块可以导入其他的模块。一个(好的)习惯是将所有的 import 语句放在模块的开始(或者是脚本),这并非强制。被导入的模块名会放入当前模块的全局符号表中
. import 语句的一个变体直接从被导入的模块中导入命名到本模块的语义表中。例如:
/*
>>> from fibo import fib, fib2
>>> fib(500)
1 1 2 3 5 8 13 21 34 55 89 144 233 377
这样不会从局域语义表中导入模块名(如上所示,fibo没有定义)
*/ . 甚至有种方式可以导入模块中的所有定义
/*
>>> from fibo import *
>>> fib(500)
1 1 2 3 5 8 13 21 34 55 89 144 233 377
这样可以导入所有除了以下划线( _ )开头的命名
*/

0x1: 编译的Python文件

为了加快加载模块的速度,Python 会在 __pycache__ 目录下以 module.version.pyc 名字缓存每个模块编译后的版本,这里的版本编制了编译后文件的格式。它通常会包含 Python 的版本号
Python 会检查源文件与编译版的修改日期以确定它是否过期并需要重新编译。这是完全自动化的过程。同时,编译后的模块是跨平台的,所以同一个库可以在不同架构的系统之间共享
Python 不检查在两个不同环境中的缓存。首先,它会永远重新编译而且不会存储直接从命令行加载的模块。其次,如果没有源模块它不会检查缓存。若要支持没有源文件(只有编译版)的发布,编译后的模块必须在源目录下,并且必须没有源文件的模块

0x2: 标准模块

Python 带有一个标准模块库,并发布有独立的文档。有一些模块内置于解释器之中,这些操作的访问接口不是语言内核的一部分,但是已经内置于解释器了。这既是为了提高效率,也是为了给系统调用等操作系统原生访问提供接口。这类模块集合是一个依赖于底层平台的配置选项。例如,winreg 模块只提供在 Windows 系统上才有。有一个具体的模块值得注意: sys这个模块内置于所有的 Python 解释器

0x3: dir() 函数

内置函数 dir() 用于按模块名搜索模块定义,它返回一个字符串类型的存储列表

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABi4AAACVCAIAAABAY5WVAAAgAElEQVR4nO2d27WsqhJAjcuAHONkYwg3CpIhkf3n/fDFo0pBEHX1nGN/9HYJ1AMKqEa7+9///vfff/91AAAAAAAAAAAAd/Lv37+OVBQAAAAAAAAAADSAVBQAAAAAAAAAADSCVBQAAAAAAAAAADSCVBQAAAAAAAAAADSCVBQAAAAAAAAAADSiYSqqH+1khtubyaEf7bRgx965uMs52mmy40PyAQAAAAAAAAD8KaJUVD9aJy2TffFx+tEm57vS7h0MqSgAAAAAAAAAgBpIp6Lms0JBkib9osRg5rNH263rhWmazDDa5VjSfARp+9te8X58aUt+zXfZcS493+vU6pcX2A9ETfu5p0jObk5Fbe0fiqSw32msdeScG3U/x3cCAAAAAAAAAPwh1Af0BiMkWdIviniHkNbn4JazVYOxY79Uttw1mKXa7UP49Nze9FK8zqko//LSSKJIMZto3WAc3XaLbZ/FOwEAAAAAAAAA/gyH74qqfTwqTEWZYb+4p6Kce+aLbtrGzx/5f4n+fEZyKipDJAHvBFhUxtcn7UQXAAAAAAAAAMAnOUhFOQd/rlwUSEpFuS9m+hupKPc+R7vR2rFXyvp3AgAAAAAAAAD8DeRU1A1vi+q61FNR7uug1qfhvAyO+4CelIraH6Y7ESz9Ab2tmTl/dChS9Kqp7b9BgmkwdhydevQ7AQAAAAAAAAD+BOIv6O2v8c6+KBO8TtyO/XJleSG4HdcUzmDsuL9Q3MnMuIXDS/6rqrbGDk9q+SI52aug1lm8+BXlgkhbDV5+y6szyHz5v0F4dCcAAAAAAAAAwB/g8F1RD+A/oPc5ej+5dEbGw4QAAAAAAAAAAN/nXamo7aTRVzM0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UsvBKCiwxFaUYRGi98w5bpdiNVBQAAAAAAAAA/FVeloqaWxqtGUdrhqUd9xyWL0lRKmp/1u/mVJR7X3zxuCEAAAAAAAAAgD9E8gN6Tg7lNFdS8i7ywRhr7dh34/ZiJUea4O1KSakoWfjBTJN36/a03VbK1yF8QE8yiNz6Vg2pKAAAAAAAAAD4beJUlP/u7jV1oj0iJ1H0q3jzu7w7/7VQm0zzW8H9N5nvIq3X1mf8VjEk4Qdjx/2yd+AputN7mbn6zKDSulecB/QAAAAAAAAA4JeRT0UVUfibeo2QHqB7B6SiAAAAAAAAAOCvckMqqvAn9ZqwHWl6l6TLCap3CQUAAAAAAAAAUIsbUlEAAAAAAAAAAAASpKIAAAAAAAAAAKARTVJRk/QPAAAAAAAAAAB+DFJRAAAAAAAAAADQCFJRAAAAAAAAAADQiH///v0fXgiQc0tiua0AAAAASUVORK5CYII=" alt="" />

该列表列出了所有类型的名称:变量,模块,函数,等等,dir() 不会列出内置函数和变量名。如果你想列出这些内容,它们在标准模块 builtins 中定义

0x4: 包

包通常是使用用"圆点模块名"的结构化模块命名空间。例如,名为 A.B 的模块表示了名为 A 的包中名为 B 的子模块。正如同用模块来保存不同的模块架构可以避免全局变量之间的相互冲突,使用圆点模块名保存像 NumPy 或 Python Imaging Library 之类的不同类库架构可以避免模块之间的命名冲突(类似于Java对包的圆点命名管理)
假设现在想要设计一个模块集(一个"包")来统一处理声音文件和声音数据。存在几种不同的声音格式(通常由它们的扩展名来标识,例如:.wav, .aiff,.au),于是,为了在不同类型的文件格式之间转换,你需要维护一个不断增长的包集合。可能你还想要对声音数据做很多不同的操作(例如混音,添加回声,应用平衡 功能,创建一个人造效果),所以你要加入一个无限流模块来执行这些操作。你的包可能会是这个样子(通过分级的文件体系来进行分组)

sound/                          Top-level package
__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
...
effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
...
filters/ Subpackage for filters
__init__.py
equalizer.py
vocoder.py
karaoke.py
...

当导入这个包时,Python 通过 sys.path 搜索路径查找包含这个包的子目录

Relevant Link:

http://www.pythondoc.com/pythontutorial3/modules.html

3. 嵌入式Python解析引擎: C++调用Python

在C/C++中嵌入Python,可以使用Python提供的强大功能,通过嵌入Python可以替代动态链接库形式的接口,这样可以方便地根据需要修改脚本代码,而不用重新编译链接二进制的动态链接库
C++调用Python有两种方式

. 第一种方式: 通过找到Python模块,类,方法,构造参数来调用
. 第二中方式: 就是通过构造出一个Python的脚本,用python引擎来执行

第一种方式可能更为优雅,符合大多数的反射调用的特点(如C#的反射机制、C#调用Com+、C#调用javascript脚本等)
这里存在的一个问题是,两种语言互相调用的时候,需要做数据结构(如基本类型、字符串、整数类型等、以及自定义的类等类型)间的转换,共享内存中的一个对象。比如,如何将C++的对象实例传入Python中,并在Python中使用。C++和Python并不在一个进程中,因此可以使用Boost的shared_ptr来实现。Python调用C++,换句话说就是需要把C++封装成Python可以"理解"的类型。同理C++去调用Python脚本也是一样的

0x1: 代码示例

test.c

/**
@file test.c
gcc -Wall -O2 -o test test.c -I/usr/include/python2.6 -L/usr/lib64/python2.6 -lpython2.6 -Wl,-R/usr/lib64/python2.6
*/
#include <stdio.h>
#include <string.h>
#include <Python.h> int main(int argc, char *argv[])
{
PyObject *pmod = NULL;
PyObject *pstr = NULL;
PyObject *pfunc = NULL;
PyObject *pargs = NULL; char *cstr = NULL; /* 初始化解释器 */
Py_Initialize(); /* 构建一个元组保存参数, PyEval_CallObject的第二参数是一个元组 */
pargs = Py_BuildValue("(s)", argv[]); /* 添加Python路径, 包括当前路径, 否则不能导入当前路径下的模块 */
PyRun_SimpleString("import sys;sys.path.append('.')"); /* 导入模块名称, 通常为调用的Python脚本程序名 */
pmod = PyImport_ImportModule("testpy");
if (pmod == NULL) {
printf("import module failed!\n");
return -;
} /* 获得导入模块的函数属性 */
pfunc = PyObject_GetAttrString(pmod, "testpy");
if (pfunc == NULL) {
printf("No such attribute!\n");
return -;
} /* 调用导入模块的入口函数, 获取返回结果 */
pstr = PyEval_CallObject(pfunc, pargs);
if (pstr == NULL) {
printf("callobject failed!\n");
return -;
} /* 分析返回的结果 */
PyArg_Parse(pstr, "s", &cstr); printf("%s\n", cstr); /* 关闭解释器 */
Py_Finalize(); return ;
}

在C程序中嵌入的Python脚本程序示例,testpy.py:

#!/usr/local/bin/python

import sys

def testpy(name):
if not name:
return 'Valid Arguments' str = "hello, " + name return str

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUkAAABBCAIAAADTzMEmAAAGkklEQVR4nO2d2ZWEIBBFjcuAjMdoTIZgnA8XtleA7dLL3Hvmo8fWAoSCauFJ1wEAAAAAwD9jdPM8z/M8De/OCcB/YfG6W32uH92SwP4h/WJjmGaP/2Y/7MY+Pzk62M52+b3djVGiO1I5Z33NaGZkmNzYj+60cXr15zlbbQmqGYxuc79aIxmm9czeX9P5DmCYZjduZ27t8KV243uVPcnzqNLJEt2R0CX1mBtZkjppPCr6yY7idD/zj4hv1dJ7u3GIh/N+i6nnuJKSg9Eg5a9ekuhjk6Vhsx/d5sMxw5QfD3zb58jnU5coKPVqsx/dPDvn0mKGpYwy7saoFEbZayXqtls0z27cbfi+bE93/2zf5CkPZLI6soq5G7net8PO18i8qrjw6OSWDJRvMiTk1TZM2y1eB51hmoOB1w+X+UF7SFkad/atbDTWCJde3Wcd0O4/sS9lJYrS3T/rWGAYBm+yTy6JPttDSsOYHYbV/t6GUYX/rG9ynnldR4WQJ7HrPe6EK6WBUZ55o+L8hT7HjNtHUL4dV0b8/3pv5cGu6NvT0OLbVuzaj26WQ9/WQPukJc7KK1S6gW8Ho/2WVmhWWAxNG82uLRqP/SwM5ZfDofFKTL5l3qgjWczMSJgRFS41Ij05PmJWXDBK+yvw7XYe8m0jCBf1rJrRMM3asUMj9i/nom/7hisafRiSRFZWV4zyL5tdLRoP8yhzvPQMke2HfPuCCFjUSZ756iOPZG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tIwgXd5n9t+O02H87HRs/ybetzBfeC5Rc9Vbfjq2HLUQYERJo9t/Whc1KxP7bccqVX1tN77hq9e3cpp1Q1gOWk6i0pad8O44whIKa/bfDHlt1OXFC7UMf+28nd8mcPdQzomYi4j7lzUHarNWmqfG3qiNvS7I6ynV0gGce1rN2pQb7b8PVsP/2J8D+2wAAAAAAAAAAAAAAABdwSGIqZ9Dv0D+juQW4gKMrIpqW713Bv9bcApynIjFtEPeKg3Ip6PGMVQKEH9bcApxHSExtCXTX5NuGqPtwxm7W7nyy5hbgPMa7R0Ki8afucpbw8/WM2Qd/VXMLcJ6q4tc+3zj4Jb790ZpbgPNoxa8dTTbF5FLUffAp9L/W3AKcxJKYVpW0ZSmsIepudG00twDfRZ+/XAAAfgCeGwMAAAAAANzHrP7gHfwBB1KUKhV97+kAAAAASUVORK5CYII=" alt="" />

Relevant Link:

http://www.qmailer.net/archives/103.html

4. Python 调用 C (base)

Python是解释性语言, 底层就是用C实现的

0x1: 代码示例

/**
@file wrapper.c
gcc -fPIC wrapper.c -o wrapper.so -shared -I/usr/include/python2.6 -I/usr/lib64/python2.6/config
*/
#include <Python.h> int fact(int n)
{
if (n <= )
return ;
else
return n * fact(n - );
} PyObject* wrap_fact(PyObject* self, PyObject* args)
{
int n, result; if (! PyArg_ParseTuple(args, "i:fact", &n))
return NULL; result = fact(n);
return Py_BuildValue("i", result);
} static PyMethodDef wrapperMethods[] =
{
{"fact", wrap_fact, METH_VARARGS, "Caculate N!"},
{NULL, NULL}
}; void initwrapper()
{
PyObject* m;
m = Py_InitModule("wrapper", wrapperMethods);
}

进入python, 可以如下使用

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfcAAABxCAIAAABHiX0BAAAQLUlEQVR4nO2d3ZGzOhBEicsBuerLhhBuFCRDML4PGPTXI0aAMWbPqX3YZUEaSdAIgVrdf//99+/fvw4AAG4JKg8AcGdQeQCAO/NFle/H1+v1er2G51eyBwD4C0iVn/T3o+r76Mcpg+WX/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PIAAHfm4yr/Uj8AAHAK/wPbMv68Ej8UEAAAAABJRU5ErkJggg==" alt="" />

Relevant Link:

http://blog.csdn.net/fxjtoday/article/details/6059874

5. 扩展Python语法解析器功能: Python中调用C++

在python中调用C++类成员函数, 如下调用TestFact类中的fact函数
wrapper.cpp

/*
g++ -fPIC wrapper.cpp -o example.so -shared -I/usr/include/python2.6 -I/usr/lib64/python2.6/config
wrapper.cpp
*/
#include <Python.h> class TestFact
{
public:
TestFact(){};
~TestFact(){};
int fact(int n);
}; int TestFact::fact(int n)
{
if (n <= )
return ;
else
return n * (n - );
} int fact(int n)
{
TestFact t;
return t.fact(n);
} PyObject* wrap_fact(PyObject* self, PyObject* args)
{
int n, result; if (! PyArg_ParseTuple(args, "i:fact", &n))
return NULL; result = fact(n);
return Py_BuildValue("i", result);
} static PyMethodDef exampleMethods[] =
{
{"fact", wrap_fact, METH_VARARGS, "Caculate N!"},
{NULL, NULL}
}; extern "C" //不加会导致找不到initexample
void initexample()
{
PyObject* m;
m = Py_InitModule("example", exampleMethods);
}

然后在有此so库的目录, 进入python, 可以如下使用

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfgAAABjCAIAAAD4nIUcAAANJ0lEQVR4nO2dW7ajIBBFHVcGlPE4GifjYLo/jPI6hYUYY3L3Xv3R1yAUBZaIchgGAAAAAAAAAAAAAAAAAAAAAAA4yHP6FzE9209uPKfNqnl87KceZ29if8phGB7jvJfOtFMW5Ct9zXMeS3tSb+vS11L2U/p5rJnWe8lajKdLaJNC5XfsrJ9e1j0xKa7OIY905imN97ZRpaC8gz2ng+0NP8hjnNce+5yq12iUckMc6macVzOeUxnvysTO3uxPuZa9UzXLTlmQs/St1OI285zmMfa2LD2cFZnf5M+6cZ4qeLqENOk5rcFzz/dW3bfTNzuXY5lJjlv4vvGH85TG+9vIKkh1sP0+DH+GOHwvV8gytlh62/b/dOgfBZFpKkdhYdTxOvgY53//5rllQL0ZtPe7L6/W0U1yjaxeeC71Ki+eyE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VDcYPw1AEelE6AMDFBPHlQwclUlS90Kcu1dtbhLCdI3pD3np5ShmyVaKlwHSD8Ubdu+XCAQDO4OyhvVRnzdXsSvX2Jn1UX6CvyFs/iq1ytMiR03hV91PkwgEA+pE7NPkPClyBfk/j/pRAX1FWfU7/5jl6bJAC037jZd3fJ5QPAODkDbP0w+Ad0SuNe78Qtld+3dL7jmb7txn6UmC6wXhVd/TDAOCTPF4vFw8e1JTKy5aas1ZvbxLC9sqvO/S+MxHxVWC6yXhDgrxXQR0A4Fu5oca9n682HgDgEm6oce/nq40HAAAAAAAAAAAAAAAAAAAAAAAAgJ/lBPH3twlLBk20pCikEQDgYr5dj34Yhj7x9y5B+9rJpezBspIWaQQAuJ43KN18i/h7pquQn54sfA3KCNM0bSrFpq5BEcOXm0JmqlcfDgCgnzP16L9K/F0MykuThiFoWsZPNvaIPjdxtSQ/gTE9AFzKSUP77xJ/L2N1xaT9k4NJiXs2e0WgRzAHAK7iPD36rxJ/z2N11aS9kwNZoJdzREsRBHoAuIKzZ+lvKv5u1SgP9KVJwxB/QRNudLYavnUzZOoGAC7nLXr0NxV/LwJ9evpatcKk6OQ8S1sNX0TwNW3kQ+I8AMDG14m/e2I4cR4AYOUbxd/LBVM5LJgCAAAAAAAAAAAAAAAAAAAAAAAAuCvLQp5SfdGlFQMAAHdnUWXJluYHqRbEWAAAfgN7B42vW5IKAAAKK9B3bcAEAAD3QcbzbasQAAD4esQ+S5NbqxIAAO5P+TL2m/TDAACgQrr13vQcyu34CPkAAAAAAAAAAAAAAAAAAJ/nn/oHAADX8h9cL1gkTr1U2QAAAABJRU5ErkJggg==" alt="" />

Relevant Link:

http://www.oschina.net/question/234345_48628
http://www.yexiwei.com/2013/06/27/python%E8%B0%83%E7%94%A8cc%E5%87%BD%E6%95%B0/

6. Python 调用 C++ (Boost.Python)

Boost库是非常强大的库, 其中的python库可以用来封装c++被python调用, 功能比较强大, 不但可以封装函数还能封装类, 类成员

Relevant Link:

http://blog.csdn.net/fxjtoday/article/details/6059874

7. python 调用 c++ (ctypes)

ctypes is an advanced ffi (Foreign Function Interface) package for Python 2.3 and higher. In Python 2.5 it is already included.
ctypes allows to call functions in dlls/shared libraries and has extensive facilities to create, access and manipulate simple and complicated C data types in Python - in other words: wrap libraries in pure Python. It is even possible to implement C callback functions in pure Python.

Relevant Link:

http://blog.csdn.net/fxjtoday/article/details/6059874

8. 脚本语言扩展性

需要明白的是,无论是Lua中调用C++扩展API,还是Python中调用C++ API,本质上都是通过外部的C++实现逻辑功能代码,通过联合编译或者so/dll的方式导入到脚本引擎中,只是区别在于python已经有大量现成的代码库和so扩展库,而Lua在这方面还很原始,很多时候还需要使用联合编译的方式实现

0x1: SWIG

有一个外部工具叫SWIG,是Simplified Wrapper and Interface Generator 的缩写。其作者为David Beazley。这个工具可以根据特别注释过的C/C++头文件生成能给Python,Tcl 和Perl 使用的包装代码。使用SWIG 可以省去你写前面所说的样板代码的时间。你只要关心怎么用C/C++解决你的实际问题就好了。你所要做的就是按SWIG 的格式编写文件,其余的就都由SWIG 来完成

0x2: Pyrex

0x3: Psyco

Psyco 的理念与其它的方法截然不同。与其改成C的代码,为何不让你已有的Python代码运行的更快一些呢?Psyco 是一个just-in-time(JIT)编译器,它能在运行时自动把字节码转为本地代码运行。所以,你只要(在运行时)导入Psyco 模块,然后告诉它要开始优化代码就可以了。而不用修改自己的代码

Relevant Link:

http://swig.org
http://cosc.canterbury.ac.nz/~greg/python/Pyrex
http://blog.csdn.net/pipisorry/article/details/49532341

Copyright (c) 2015 LittleHann All rights reserved

python grammar、C/C++ Python Parsing Engine的更多相关文章

  1. 【python 字典、json】python字典和Json的相互转换

    [python 字典.json]python字典和Json的相互转换 dump/dumps字典转换成json load/loadsjson转化成字典 dumps.loads直接输出字符 dump.lo ...

  2. 在windows中:双击运行Python程序、后台运行Python程序

    在windows中:双击运行Python程序.后台运行Python程序 安装Python解释器的windows环境,如果双击运行*.py的文件,会闪退.怎样避免闪退呢? 我们用python的日志输出程 ...

  3. 1、[python] PyMouse、PyKeyboard用python操作鼠标和键盘

    [python] PyMouse.PyKeyboard用python操作鼠标和键盘 1.PyUserInput 简介 PyUserInput是一个使用python的跨平台的操作鼠标和键盘的模块,非常方 ...

  4. [python] PyMouse、PyKeyboard用python操作鼠标和键盘

      1.PyUserInput 简介 PyUserInput是一个使用python的跨平台的操作鼠标和键盘的模块,非常方便使用.支持的平台及依赖如下: Linux - Xlib Mac - Quart ...

  5. python简介、第一个python程序、变量、字符编码、用户交互程序、if...else、while、for

    也愿大家永葆初心-- 已识乾坤大,犹怜草木青. 一.python简介 首先,我们普及一下编程语言的基础知识.用任何编程语言来开发程序,都是为了让计算机干活,比如下载一个MP3,编写一个文档等等,而计算 ...

  6. Python之一、#!/usr/bin/python到底是什么意思

    引用https://www.cnblogs.com/furuihua/p/11213486.html 关于脚本第一行的 #!/usr/bin/python 的解释,相信很多不熟悉 Linux 系统的同 ...

  7. Python框架、库以及软件资源汇总

    转自:http://developer.51cto.com/art/201507/483510.htm 很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世 ...

  8. 【python】Python框架、库和软件资源大全

    很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世界各地的程序员们都能够贡献他们的代码与创新. Python就是这样一门受到全世界各地开源社区支持的语言. ...

  9. Python框架、库和软件资源大全(整理篇)

    有少量修改,请访问原始链接.PythonWIn的exe安装包;http://www.lfd.uci.edu/~gohlke/pythonlibs/ 原文链接:codecloud.net/python- ...

随机推荐

  1. JSP中的Servlet及Filter

    asp.net中,如果开发人员想自己处理http请求响应,可以利用HttpHandler来满足这一要求:类似的,如果要拦截所有http请求,可以使用HttpMoudle.java的web开发中,也有类 ...

  2. Orchard CMS中如何打包不带源码的模块

    在Orchard CMS的官网已经提供了文档说明如何打包,但是如果使用它的打包方式,打好的nuget包是带源代码的.如果是为开源系统写模块,不需要关注源代码是否可见.但是如果是用Orchard CMS ...

  3. JavaScript系列:计算一个结果为30的加法智力题

    用下面这段JavaScript代码可以计算出来 function findTheThreeNum(numFix) { var a = ["1", "3", &q ...

  4. 【语言基础】c++ 备忘录

    1. C++ 整数类型范围 可以参照头文件limits.h定义的宏 #define INT_MAX       2147483647(32bit, 最大10位十进制) #define UINT_MAX ...

  5. CSS 颜色代码大全

    CSS颜色: 转载:http://www.cnblogs.com/axing/archive/2011/04/09/CSS.html

  6. matlab 功率谱分析

    matlab 功率谱分析 1.直接法:直接法又称周期图法,它是把随机序列x(n)的N个观测数据视为一能量有限的序列,直接计算x(n)的离散傅立叶变换,得X(k),然后再取其幅值的平方,并除以N,作为序 ...

  7. STL中的next_permutation

    给定一个数组a[N],求下一个数组. 2 1 3 4 2 1 4 3 2 3 1 4 2 3 4 1 ..... 在STL中就有这个函数: 1.参数是(数组的第一个元素,数组的末尾),注意这是前闭后开 ...

  8. java web 100个知识点

    http://wenku.baidu.com/link?url=ns5SvKesJSLzpcTckBKsFopqgbC6O0XBuVBS1BZwtJbK1P-aYbNV3fVOU9lYTbGQwKYK ...

  9. IOS -- 获取本地图片和网络图片的大小size

    // 获取图片的size CGSize size = [UIImage imageNamed:@"regStep2_sex"].size; 获取网络图片的尺寸: // 根据图片ur ...

  10. C#高级特性_Attribute

    Attribute: 公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法和属性等.Attributes和Microsoft .NET ...