首页 > 编程语言 > 详细

python sys.sdout.write 和print 区别

时间:2015-01-16 15:56:00      阅读:349      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!