Raj*_*ath 12 python python-3.x python-3.3
这是在嵌套列表中打印所有值的功能(首先从Python获取).
def printall(the_list, level):
for x in the_list:
if isinstance(x, list):
printall(x, level=level + 1)
else:
for tab_stop in range(level):
print("\t", end='')
print(x)
Run Code Online (Sandbox Code Playgroud)
功能正常.
该函数基本上打印列表中的值,如果有嵌套列表,则按标签空间打印.
只是为了更好地理解,做end=' '什么?
我使用的是Python 3.3.5
对于2.7
f = fi.input( files = 'test2.py', inplace = True, backup = '.bak')
for line in f:
if fi.lineno() == 4:
print line + '\n'
print 'extra line'
else:
print line + '\n'
Run Code Online (Sandbox Code Playgroud)
截至2.6 fileinput不支持.此代码附加3行,并在第3个新行上打印附加文本.然后再添加16个空行.
Bha*_*Rao 31
默认值end是\n指在print语句之后它将打印一个新行.所以简单说明end是print在执行语句后要打印的内容
例如: - print ("hello",end=" +")将打印hello +