讓Python輸出更漂亮—Print
- 2020 年 1 月 8 日
- 筆記
print 默認輸出是換行的,如果要實現不換行需要在變數末尾加上 end="":
student_age=18
print("學生的年齡為:",student_age)
#print("學生的年齡為:"),print(student_age)中間不換行
#print執行完後默認換行
print("hello,world!",end="n")
print("hello,world!",end="") # 不換行
print("hello,world!",end="")

print("Abby","Candy","Tina","Sandy",sep="==")
sep 分隔符

如:
money = 121
print("本次消費金額為:",money,sep="$")

print還可以把內容輸出到文件
str01 = "本次消費金額為:$128"
file01 = open("d:sales.txt","w")
print(str01,file=file01) #文件輸出會有異常,需要異常處理