python2.X 打印输出时如何不换行
# -*- coding:utf-8 -*-
import random
rooms = [[],[],[]]
teachers = ["A","B","C","D","E","F","G","H"]
for name in teachers:
randomNum = random.randint(0,2)
rooms[randomNum].append(name)
i = 1
for room in rooms:
print("办公室%d老师的名字是:"%i)
for name in room:
#这里在print后面加一个逗号,可以不换行显示
print(name),
print("")
i += 1
这里实现的是一个很简单的功能,遍历各个办公室老师的名称,很不可思议!
借鉴博客:http://blog.csdn.net/leos_blog/article/details/17529621