Python output?

Joined
Mar 29, 2023
Messages
15
Reaction score
1
I am learning Python3 and while doing some revision i wrote out a simple 'for loop' and noticed that when i wanted the output on an
horizontal level it outputted the string and the python prompt on the same line.

Here is a sample of Python code i used:

Code:
         >>> programming = 'python.code'
         
         >>> for program in programming :
         ...    print(program)
         ...
       python.code>>>

I have tried using the print() function like print(program, end='\n')
But this results in the output being printed on a vertical line.

Hope someone can help a noob like myself.

Thanks all
 
Joined
Jul 4, 2023
Messages
573
Reaction score
77
Have you tried?
Python:
programming = 'python.code'
for program in programming:
  print(program, end='')
print('\n')
 
Joined
Jan 14, 2025
Messages
20
Reaction score
5
I am learning Python3 and while doing some revision i wrote out a simple 'for loop' and noticed that when i wanted the output on an
horizontal level it outputted the string and the python prompt on the same line.

Here is a sample of Python code i used:

Code:
         >>> programming = 'python.code'
        
         >>> for program in programming :
         ...    print(program)
         ...
       python.code>>>

I have tried using the print() function like print(program, end='\n')
But this results in the output being printed on a vertical line.

Hope someone can help a noob like myself.

Thanks all
The issues you face are from the "\n" part. This creates a new line.
Modify the print() function by using the end parameter. Setting end='' will prevent the newline character from being added after each print statement.

What VBService posted is a perfect example:
Code:
programming = 'python.code' 
for program in programming:    
print(program, end='')
Hope this helps :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,068
Members
47,674
Latest member
scazeho

Latest Threads

Top