---
title: "python2.7 print不换行的三种方法"
author: "heipark"
date: "2015-07-30T10:54:12Z"
tags: []
categories: ["编程语言"]
slug: "python2-7-print"
draft: false
lastmod: "2015-07-30T11:00:19Z"
id: 2231545
url: "https://heipark.iteye.com/blog/2231545"
---

方法一：

```
import sys

sys.stdout.write("go ")
sys.stdout.write("home")

sys.stdout.flush()
```

 

 方法二：函数方式调用print函数

```
from __future__ import print_function

print('go ', end='')
print('home', end='')
```

 

方法三：

 

```
print 'go', 
print 'home'
```

 这种方法如果你直接执行python执行命令，然后敲入命令，是不行的，但如果放到文件里面运行，是可以的

 

-end