Make Python output prettier ---Print output

The default output of print is newline. If you want to achieve no newline, you need to add  end="" at the end of the variable :

 

student_age=18

print ( " The age of the student is: " , student_age )

#print(" The age of the student is: "), print(student_age) without line break

 

 

#print wraps by default after execution

print("hello,world!",end="\n")

print("hello,world!",end="") # 不换行

print("hello,world!",end="")

12.png


print("Abby","Candy","Tina","Sandy",sep="==")

 

sep  separator

13.png


Such as:

money 121

print ( " The amount of this consumption is: " , money , sep = "$" )


14.png


print can also output content to a file

str01  " This consumption amount is: $128"

file01 open("d:\sales.txt","w")

print ( str01 , file = file01) #There  will be exceptions in file output, and exception handling is required


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324714332&siteId=291194637