Add-ons to your Python code to make it better!

Hello hello hello wassup people,

I’m just going to show you some quick things to make your Python code cool!

1) Screen Clearing

Screen clearing is very useful; you use it to, well, clear the screen. I like it a lot because you can use it to erase everything so that it looks better, and so that not too much text crowds the screen!

For the screen clearing, you need to just:

You can copy this code and put it every time you need to.
However, i prefer to create a function, so that i dont need to keep putting that (even if its just a few letters...):

As you can see I called the function sc(),which stands for screen clear, so each time I want to clear the screen, i just call that function. It makes it just a bit shorter.
(Thanks to @ArjunSS1 for helping me with the screen clear)

2) Typewriter effect

Now this typewriter effect is super cool, because it makes the text print one letter at the time. You can regulate it so that it prints the text fast or slow.
First the imports:

And this is the code:

I usually put it at 0.04because it prints it not too fast and not too slow. But you can change it. Just change the value after st

Each time you want to do this typewriter effect, just do:


3) While loops to go back to menu (very basic)

Personally, I’m not a pro in loops, but this is what I do sometimes. Imagine you want to do sort of menu option, like this:

So when the user types hello, several greetings will appear. But what if the user types something else by accident? Then, you could add an else statement, and saying something like “invalid”, and then the user could return to the menu,
This is how you do that:

So when you put back_to_menu = True at the end of the else statement, the user will arrive back at the menu!

4) Colors

This is how to make colors in Python.

Pretty simple, just copy paste these colors (because typing them would be to long...)

So to use it, just put the color before the text:

This also works with the slowPrintI mentioned earlier

5) Some functions you can use

I always use these functions in my code because they are kinda like shortcuts. Less is more!

So that’s about it i know this tutorial isn’t very good, but I hope it helped you and you enjoyed it.
Lastly, nothing is under copyright, so go on and copy paste!

Tips, suggestions, questions, comments to let me know stuff, etc. Feel free to contact me!

You are viewing a single comment. View All

Small things, good article but you could do these things

You can use os to clear the screen instead like os.system('clear') which clears the screen
For the typewriter there is an inbuilt argument in your print statement so instead of running sys.stdout.flush() you can just print(char, end='', flush=True)

Intead of running whille_back_to_menu = True you can just run while back_to_menu which is true so it will loop alternatively you can run while 1: which is True and you add a break statement to the if action1 == 'hello' block.


Also you can print a certain string to clear the screen also. @ArjunSS1


Hey, thanks for commenting! I’m gonna change the screen clear and out your name for credit @ArjunSS1
Also for the typewriter I just put a function so that it’s shorter
For the back to menu, I know it can always loop back, but sometimes the user wants to just go to another thing instead of looping back.

But anyways thanks for the comments and remember,