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) #文件输出会有异常,需要异常处理
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有