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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM