简明概述
Last updated
class A:
def __init__(self):
pass
def hello(self):
pass
def main():
pass # 正确的写法
import os
import sys
# 不推荐的写法
import sys,os
# 正确的写法
from subprocess import Popen, PIPE# 正确的写法
from foo.bar import Bar
# 不推荐的写法
from ..bar import Barimport os
import sys
import msgpack
import zmq
import foofrom myclass import MyClassimport bar
import foo.bar
bar.Bar()
foo.bar.Bar()# 正确的写法
i = i + 1
submitted += 1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)
# 不推荐的写法
i=i+1
submitted +=1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)# 正确的写法
def complex(real, imag):
pass
# 不推荐的写法
def complex(real,imag):
pass# 正确的写法
def complex(real, imag=0.0):
pass
# 不推荐的写法
def complex(real, imag = 0.0):
pass# 正确的写法
spam(ham[1], {eggs: 2})
# 不推荐的写法
spam( ham[1], { eggs : 2 } )# 正确的写法
dict['key'] = list[index]
# 不推荐的写法
dict ['key'] = list [index]# 正确的写法
x = 1
y = 2
long_variable = 3
# 不推荐的写法
x = 1
y = 2
long_variable = 3foo = long_function_name(var_one, var_two,
var_three, var_four)def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)session.query(MyTable).\
filter_by(id=1).\
one()
print 'Hello, '\
'%s %s!' %\
('Harry', 'Potter')# 正确的写法
do_first()
do_second()
do_third()
# 不推荐的写法
do_first();do_second();do_third();# 正确的写法
if foo == 'blah':
do_blah_thing()
# 不推荐的写法
if foo == 'blah': do_blash_thing()"""Return a foobar
Optional plotz says to frobnicate the bizbaz first.
"""
"""Oneline docstring"""