![]() |
傻傻的馒头 · Python 运算符| 菜鸟教程· 1 年前 · |
![]() |
傻傻的馒头 · Flex 布局语法教程| 菜鸟教程· 1 年前 · |
![]() |
傻傻的馒头 · Rust 教程| 菜鸟教程· 1 年前 · |
![]() |
傻傻的馒头 · TypeScript 教程| 菜鸟教程· 1 年前 · |
![]() |
傻傻的馒头 · C++ 教程| 菜鸟教程· 1 年前 · |
发布版本
|
源自
|
年份
|
所有者
|
GPL兼容
|
0.9.0至1.2
|
n/a
|
1991-1995
|
CWI
|
是
|
1.3至1.5.2
|
1.2
|
1995-1999
|
CNRI
|
是
|
1.6
|
1.5.2
|
2000
|
CNRI
|
否
|
2.0
|
1.6
|
2000
|
BeOpen.com
|
否
|
1.6.1
|
1.6
|
2001
|
CNRI
|
否
|
2.1
|
2.0+1.6.1
|
2001
|
PSF
|
否
|
2.0.1
|
2.0+1.6.1
|
2001
|
PSF
|
是
|
2.1.1
|
2.1+2.0.1
|
2001
|
PSF
|
是
|
2.1.2
|
2.1.1
|
2002
|
PSF
|
是
|
2.1.3
|
2.1.2
|
2002
|
PSF
|
是
|
2.2 至3.
|
2.1.1
|
2001至今
|
PSF
|
是
|
3.0及更高
|
2.6
|
2008至今
|
PSF
|
是
|
age = int(input("请输入你的年龄: ")) if age < 21: print("你不能买酒。") print("不过你能买口香糖。") print("这句话在if语句块的外面。")
>>> sum(x * x for x in range(10)) 285
>>> add=lambda x, y : x + y >>> add(3,2) 5
>>> x, y=1,2 # 同时给x,y赋值,最终结果:x=1, y=2
>>> x, y=y, x #最终结果:y=1, x=2
class Fish: def eat(self,food): if food is not None: self.hungry=False class User: def __init__(myself,name): myself.name=name #构造Fish的实例: f=Fish() #以下两种调用形式是等价的: Fish.eat(f,"earthworm") f.eat("earthworm") u=User('username') print(u.name)
类型
|
描述
|
例子
|
备注
|
---|---|---|---|
str
(string/字符串)
|
一个由字符组成的不可更改的有序串行。
|
"""Spanning
multiple
lines"""
|
在Python 3.x里,字符串由Unicode字符组成
|
bytes(字节)
|
一个由字节组成的不可更改的有序串行。
|
b'Some ASCII'
b"Some ASCII"
|
在Python 2.x里,bytes为str的一种
|
list(列表)
|
可以包含多种类型的可改变的有序串行
|
[4.0,'string',True]
|
无
|
tuple(元组)
|
可以包含多种类型的不可改变的有序串行
|
(4.0,'string',True)
|
无
|
set,frozenset
|
与数学中集合的概念类似。无序的、每个元素都是唯一的。
|
{4.0,'string',True}
frozenset([4.0,'string',True])
|
无
|
dict(字典)
|
一个可改变的由键值对组成的无序串行。
|
{'key1':1.0,3:False}
|
无
|
int(整数)
|
精度不限的整数
|
42
|
无
|
float(浮点数)
|
浮点数。精度与系统相关。
|
3.1415927
|
无
|
complex
|
复数
|
3+2.7j
|
无
|
bool
|
逻辑值。只有两个值:真、假
|
True
False
|
无
|
builtin_function_or_method
|
自带的函数,不可更改也不可增加
|
print
input
|
无
|
type(类型)
|
显示某个值的类型,用type(x)获得
|
type(1)->int
type(‘1’)->str
|
无
|
range
|
按顺序排列的数
|
range(10)
......list(range(10))->[0,1,2,3,4,5,6,7,8,9]
range(1,10)
......list(range(1,10)->[1,2,3,4,5,6,7,8,9]
range(1,10,2)
......list(range(1,10,2))->[1,3,5,7,9]
|
在Python 2.x中,range为builtin_function_or_method,获得的数为list
|
>>>import math >>>dir(math) ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
>>>help(sum) Help on built-in function sum in module builtins: sum(iterable, start=0, /) Return the sum of a 'start' value (default: 0) plus an iterable of numbers When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types.
<Directory"/var/www/cgi-bin"> Allow Override None Options ExecCGI Order allow,deny Allow from all </Directory> <Directory"/var/www/cgi-bin"> Options All </Directory>
#!/usr/bin/env python print("Content-type:text/html\r\n\r\n") print("<html>") print("<head>") print("") print("</head>") print("<body>") print("<h2>Hello World! This is my first CGI program</h2>") print("</body>") print("</html>")
Hello World! This is my first CGI program
变量名
|
描述
|
---|---|
CONTENT_TYPE
|
这个环境变量的值指示所传递来的信息的MIME类型。目前,环境变量CONTENT_TYPE一般都是:application/x-www-form-urlencoded,他表示数据来自于HTML表单。
|
CONTENT_LENGTH
|
如果服务器与CGI程序信息的传递方式是POST,这个环境变量即使从标准输入STDIN中可以读到的有效数据的字节数。这个环境变量在读取所输入的数据时必须使用。
|
HTTP_COOKIE
|
客户机内的 COOKIE 内容。
|
HTTP_USER_AGENT
|
提供包含了版本数或其他专有数据的客户浏览器信息。
|
PATH_INFO
|
这个环境变量的值表示紧接在CGI程序名之后的其他路径信息。它常常作为CGI程序的参数出现。
|
QUERY_STRING
|
如果服务器与CGI程序信息的传递方式是GET,这个环境变量的值即使所传递的信息。这个信息经跟在CGI程序名的后面,两者中间用一个问号'?'分隔。
|
REMOTE_ADDR
|
这个环境变量的值是发送请求的客户机的IP地址,例如上面的192.168.1.67。这个值总是存在的。而且它是Web客户机需要提供给Web服务器的唯一标识,可以在CGI程序中用它来区分不同的Web客户机。
|
REMOTE_HOST
|
这个环境变量的值包含发送CGI请求的客户机的主机名。如果不支持你想查询,则无需定义此环境变量。
|
REQUEST_METHOD
|
提供脚本被调用的方法。对于使用 HTTP/1.0 协议的脚本,仅 GET 和 POST 有意义。
|
SCRIPT_FILENAME
|
CGI脚本的完整路径
|
SCRIPT_NAME
|
CGI脚本的的名称
|
SERVER_NAME
|
这是你的 WEB 服务器的主机名、别名或IP地址。
|
SERVER_SOFTWARE
|
这个环境变量的值包含了调用CGI程序的HTTP服务器的名称和版本号。例如,上面的值为Apache/2.2.14(Unix)
|
#!/usr/bin/python import os print("Content-type:text/html\r\n\r\n") print("Environment") for param in os.environ.keys(): print"<b>%20s</b>:%s<\br>" %(param,os.environ[param])
import urllib2 #调用urllib2 url='http://www.baidu.com/s?wd=cloga' #把等号右边的网址赋值给url html=urllib2.urlopen(url).read() #html随意取名 等号后面的动作是打开源代码页面,并阅读 print html #打印
![]() |
傻傻的馒头 · Python 运算符| 菜鸟教程 1 年前 |
![]() |
傻傻的馒头 · Flex 布局语法教程| 菜鸟教程 1 年前 |
![]() |
傻傻的馒头 · Rust 教程| 菜鸟教程 1 年前 |
![]() |
傻傻的馒头 · TypeScript 教程| 菜鸟教程 1 年前 |
![]() |
傻傻的馒头 · C++ 教程| 菜鸟教程 1 年前 |