Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of printing without newline characters in Python

Shulou Source: shulou.com Published: 2022-06-01 22:48:51 09月29日 Update

Most people do not understand the knowledge points of this article "print without line breaks in Python", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "the method of printing without line breaks in Python".

I. brief introduction

Printing or logging is the most common thing in any programming language and one of the most common things everyone likes to do. By default, in python programming, each printout is written on a different line. To print without wrapping, we simply add a parameter to the print statement or use the built-in Python library (that is, sys).

Second, how to print without line wrapping in Python

I use JetBrains PyCharm as my preferred IDE. You are also free to choose the IDE you like.

How to print without line wrapping in Python

Let's understand this with the help of code snippets.

Single inheritance

# print without newline in python 3.x# python inbuilt library to print without newlineimport sysdef simple (): print ('Hellograms, end=' It is friday today. ') Print ('Have a great weekend.') def loop (): cars = [' Ford', 'Volvo',' Audi', 'Mercedes',' Toyota'] for car in cars: print (car, end='') def using_sys (): sys.stdout.write ('Hello! It is friday today.') Sys.stdout.write ('Have a great weekend.') def main (): simple () print ('\ n =\ n') loop () print ('\ n =\ n') using_sys () if _ _ name__ = ='_ _ main__': main ()

If all goes well, the following output appears in the IDE console.

Console output

Hello! It is friday today. Have a great weekend.=Ford Volvo Audi Mercedes Toyota = Hello! It is friday today. Have a great weekend. The above is about the content of this article on "printing without newline characters in Python". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Content newline character method output things common situation console article knowledge article help control programming difference freedom lieutenant general code value parameter Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Redmi Huawei Shulou Information