Learn to Code via Tutorials on Repl.it!

← Back to all posts
sep = ..., end = ..., and flush = ...
CodingEssence (126)

sep = ..., end = ..., and flush = ...

OK, be patient. Just read the tutorial. It tells you what these are

Couldn't think of a good intro XD

sep = ...

None of these keywords are hard to learn unless you don't know what print is: oof if you know what print() is.

For example, if you were were doing this:

print('Hello', 'I am CodingEssence', 'I am 12 years old')

I would get this (According to my output):

Hello I am CodingEssence I am 12 years old

Simple, right.

What about if you wanted a certain character(s) in between those strings? You would use sep.

You can assign a certain character(s) to sep and will automatically out them in between them.

Let's say I wanted a new line between each string. We would do:

print('Hello', 'I am CodingEssence', 'I am 12 years old', sep = '\n')

This would output:

Hello
I am CodingEssence
I am 12 years old

end = ...

end is pretty similar to sep. end just chooses what will be printed at the end of every line that is printed using print()

Just remember, if you use end and assign a string or number or whatever, you need to add a new line, otherwise the next print() statement will print on the same line.

For example:

print('Hello', end = ' ')
print('I am CodingEssence', end = ' ')
print('I am 12 years old', end = '!')

This would output:

Hello I am CodingEssence I am 12 years old!

flush = ...

flush doesn't actually make sense to me, but I'll try to explain it the best I can.

Output from print() goes into a buffer. When you change the end parameter, the buffer no longer gets flushed. To ensure that you get output as soon as print() is called, you also need to use the flush = True parameter. (Referenced from Real Python)

If you still don't understand flush, please go here

If you would like to see end and flush in action, please visit my other tutorial: TypeWriter


Please check out my Racing Simulator


Please give me more ideas on what to code, I don't have any more ideas.


That's it for this Tutorial. Hope you benefit from this. Bye!

Comments
hotnewtop
DillonB07 (25)

Please give me more ideas on what to code, I don't have no more ideas.

I like the double negative! It means that you do have ideas!

CodingEssence (126)

@DillonB07 lol i actually meant to say I don't have any more ideas

DillonB07 (25)

I guessed that @CodingEssence. But, what about a text-based adventure game(T-BAG)?

DynamicSquid (5023)

flush doesn't actually make sense to me

Try to think of it as an array that stores the output. We store characters in that array until it's full, or until it gets flushed to the console. We do this since outputting characters to the console is sloooow.

Your explanation of it was good :)

CodingEssence (126)

@DynamicSquid thanks! Makes much more sense now!

[deleted]

@DynamicSquid you're? its your... 😅