M
M
Max Kachuriak2021-08-28 21:56:31
Python
Max Kachuriak, 2021-08-28 21:56:31

How to join lines?

For example, I have the following command
Print('hello')
Print('world')
How to connect them? I know this can be written in one line, but how to connect if so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Gusarev, 2021-08-29
@kaka888

There are several ways:

print('Hello ' + 'world')  # 1-й способ

print('Hello', 'world', sep=' ')  # 2-й способ

# 3-й способ
print('Hello', end=' ')
print('world')

The "+" operator glues two lines into one (or, in the case of numbers, adds 2 numbers).
The named parameter "sep" of the print function determines how the lines passed to the print function, separated by commas, will be separated on the screen.
The named parameter "end" of the print function determines what will be put at the end of the printed text (line). By default end = '\n', i.e. at the end there will be a newline character. "\n" means go down to a new line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question