码迷,mamicode.com
首页 > 编程语言 > 详细

python sys.sdout.write 和print 区别

时间:2015-01-16 15:56:57      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

sys.sdout.write 标准输入相当于“%value%”,输出内容没有空格,而print输出带有空格,举个例子

 

用sys.sdout.write;

import sys
for i in range(1,11):
    for j in range(1,i+1):
        #print"##",
       sys.stdout.write("$$")

    print ""

输出

$$
$$$$
$$$$$$
$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$
import sys
for i in range(1,11):
    for j in range(1,i+1):
        print"##",
       #sys.stdout.write("$$")

    print ""

#输出
## 
## ## 
## ## ## 
## ## ## ## 
## ## ## ## ## 
## ## ## ## ## ## 
## ## ## ## ## ## ## 
## ## ## ## ## ## ## ## 
## ## ## ## ## ## ## ## ## 
## ## ## ## ## ## ## ## ## ## 

 

python sys.sdout.write 和print 区别

标签:

原文地址:http://www.cnblogs.com/chenya/p/4228663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!