derezzed

导航

print的区别

在py2中print是一个语法结构,而在py3中print是一个函数,

print(value, ..., sep=' ', end='\n',file=sys.stdout, flush=False) 

file可以是文件,也就是可以把打印的东西直接输出到文件,这个就很方便,我经常用。比如:

a = range(10)

out_file = open(“print_test_file.txt”, ‘w’)

for x in a:

       print(x,sep=’ ‘, end = “\n”, file=out_file)

 另外:

 

posted on 2018-01-07 17:04  derezzed  阅读(171)  评论(0)    收藏  举报