The four/4 strong different Python commands that perform the same task – Interesting!!!

Users might be asking, same time, wondering about the commands that perform the same job or task in the Python environment. A programmer never relies only on a particular syntax.

Consider the below:

COMMAND NO.1

print

To enter the command correctly, we go by this:

print(“Love is Good”)

The above is known to be a single-line Python command or code that performs a simple task. The print is marked as a Python built-in function or syntax that outputs the value passed to it to the console. In summary, this command displays the text or values to the user or an individual.

The text(“Love is Good”)

It is known to be a string literal, which is a sequence of characters enclosed in quotes. In this case, that is the text called Love is Good.

COMMAND NO.2

the import sys

and “sys.stdout.write(“Love is Good\n”)

The line 1,  consists of the import sys inserts or imports of the entire sys module which enables and provides access to some variables and functions used or even maintained by the interpreter and also to functions that interact strongly with the interpreter.

 

The second line, which is line number 2 has sys.stdout.write(“Love is Good\n”; this particular line uses the write() from the sys.stdout object to print the string GOOD. However, followed by a new given line character, that is (\n), to the standard output, which is also called the console.

NB:

The sys.stdout is known as a file object that represents the standard stream.

COMMAND NO.3

The import os input technique:

import os

os.system(‘echo Hello World!)

 

Finally, the creative syntax:

My_string = “I am the best”; print((my_string+” ”)*2)

Related posts:

About Author


Discover more from SURFCLOUD TECHNOLOGY

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from SURFCLOUD TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading