After reading the intresting articles of vegaseat, I finally decided to get my toes wet.
So I installed Pyton 3.3.2 amd the plugin for Visual Studio 2010.
The best learning is of course practice, so I started coding right away.
Here is my first try:

import sys
print('Hello World')
print('I like internet for:')
for item in ['email', 'surfing', 'home']:

This works,but if I want to eliminate the newline, auto added by the print function, nothing is printed.
Google proposed, end, sep and comma, but nothing seems to work.
Anyone any ideas?
Thanks in advance for a solution.

Recommended Answers

All 8 Replies

How about using sys.stdout.write(item)

IIRC using print should be this: print(item, end="")

Thans for the answer pritaeas.
I already tried both options, but for some reason nothing is printed.

I found out.
It appears you have to flush the output stream print(item,end=" ",flush=True) What could be a reason to do it this way?

for item in ['email', 'surfing', 'home']: 
    print(item, end='', flush= True)


for item in ['email', 'surfing', 'home']: 
    print(item, end='')

I found someone who came up with a good argument why it is that way:
klick me

commented: Exellent Click me! +14
commented: excellent! +14

Thanks for the answers.

Could be your IDE acting up.
Also your line 6 needs to be print()

No need to putz around with sys

@vegaseat: Could be I'm still an absolute beginner in Python, but I'm learning.
This is what I think my problem was:
When I tried to put all tree strings on one line, I used a print function and suppressed the newline. But I closed of with a print statement (see line 6) Which I guess does nothing, not even print a newline. When I use a print function print() it works! Correct me if I'm wrong.

Starting with Python3 the print statement has been replaced with a much more useful print() function. There is still a lot of Python2 code around, so be aware. Enjoy Python!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.