Home  >  Article  >  Backend Development  >  How to print python output on only one line

How to print python output on only one line

尚
Original
2019-06-26 17:04:437329browse

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

The execution result of the above example is:

a
b
---------
a b a b

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!

Statement:
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