1 # 交换两个变量的值,packaging/unpackaging机制 2 x = 2 3 y = 3 4 x, y = y, x 5 print x, y
1 # 字符串格式化 2 print ‘Hello %(name)s!‘ % {‘name‘: ‘Tom‘}
1 # 字符串格式化 2 print ‘Hello {name}!‘.format(name=‘Tom‘)
1 C:\>pip install -U pep8 2 3 C:\Users\Administrator\Desktop\zxt>pep8 --first database.py 4 database.py:83:1: E302 expected 2 blank lines, found 1 5 6 >pep8 --show-source --show-pep8 waijiao.py
1 n = raw_input("please input a number:") 2 if n == "0": 3 print "You typed zero." 4 elif n == "1": 5 print "You are in top." 6 elif n == "2": 7 print "N is an even number." 8 else: 9 print "Error!"
1 def func(): 2 return { 3 "0": "You typed zero.", 4 "1": "You are in top.", 5 "2": "N is an even number." 6 }.get(n, "Error!")
1 """ 2 Requests HTTP library 3 ~~~~~~~~~~~~~~~~~~~~~ 4 Requests is an HTTP library, written in Python, for human beings. Basic GET 5 usage: 6 >>> import requests 7 >>> r = requests.get(‘https://www.python.org‘) 8 >>> r.status_code 9 200 10 >>> ‘Python is a programming language‘ in r.content 11 True 12 ... or POST: 13 >>> payload = dict(key1=‘value1‘, key2=‘value2‘) 14 >>> r = requests.post(‘http://httpbin.org/post‘, data=payload) 15 >>> print(r.text) 16 { 17 ... 18 "form": { 19 "key2": "value2", 20 "key1": "value1" 21 }, 22 ... 23 } 24 The other HTTP methods are supported - see `requests.api`. Full documentation 25 is at <http://python-requests.org>. 26 :copyright: (c) 2015 by Kenneth Reitz. 27 :license: Apache 2.0, see LICENSE for more details. 28 """
1 # -*-coding:UTF-8 -*- 2 3 import sys 4 5 6 class _const(object): 7 8 class ConstError(TypeError): 9 pass 10 11 class ConstCaseError(ConstError): 12 pass 13 14 def __setattr__(self, name, value): 15 if self.__dict__.has_key(name): 16 raise self.ConstError, "Can‘t change const.{name}".format(name=name) 17 if not name.isupper(): 18 raise self.ConstCaseError, ‘const name "{name}" is not all uppercase‘.format(name=name) 19 self.__dict__[name] = value 20 21 22 sys.modules[__name__] = _const()
原文:https://www.cnblogs.com/zhangbc/p/10285549.html