Skill - Basic printing in python
Skills Required
Please make sure to go through all the skills mentioned above to understand and execute the code mentioned below
Main Code
In order to print the Hello world! string, use the print() function as follows
print("Hello world!")
‘end’ input to suppress new line
use ‘end’ input to print function to suppress new line for each print function call
# space printed at the end instead of new line
print('Hello', end=' ')
# space printed at the end instead of new line
print('World', end=' ')
print('!!!')
colored printing using the ‘colored’ module
Use pip install colored
in command prompt to install colored
module
# import fg, bg, attr sub modules from colored module
from colored import fg, bg, attr
# print Hello World !!! with red foreground and blue background
print ('{0}{1}Hello World !!!{2}'.format(fg('red'), bg('blue'), attr('reset')))
# print Hello World !!! with green color
print ('{0}Hello World !!!{1}'.format(fg('green'), attr('reset')))
For more information on colors in colored
module click here
Run this in Visual Studio Code
- Create a folder in your PC
- Open this folder in Visual Studio Code using menu File->Open Folder
- Open File Explorer
- Create a python file by any name, say
hello.py
and write the following
print("Hello world!")
- Run the code using menu Run -> Run Without Debugging
- You should see Hello world! printed in the terminal
Video
The video for this post can be seen here
Online Interpreter
You can run these codes online at https://www.programiz.com/python-programming/online-compiler/
References
- Official documentation - https://docs.python.org/3/library/functions.html#print
colored
module - https://pypi.org/project/colored/- Colored printing guide - https://www.geeksforgeeks.org/print-colors-python-terminal/
Comments
Post a Comment