How to print python output on only one line

Release: 2019-07-08 09:02:52
Original
7342 people have browsed it

How to print python output on only one line

The default output of print in Python is line wrapping. If you want to achieve no line wrapping, you need to add a comma at the end of the variable.

Example:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
x="a"
y="b"
# 换行输出
print x
print y
print '---------'
# 不换行输出
print x,
print y,
# 不换行输出
print x,y
Copy after login

The execution result of the above example is:

a
b
---------
a b a b
Copy after login

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to print python output on only one line. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template