×

End Parameter in python

print():

The python print() function prints the program’s output to the output screen. The output can be an integer value, string value or other value.

Syntax:

print(“hi”)

Output:

hi will be displayed on the output screen.

Parameters:

Object Parameter:

The object can be any value like integer, float, etc. This indicates that the object should be printed on the output screen.

Example:

#simple program for print() function
Print(“hi”, ”hello”)

Output:

hi hello

Here hi and hello are considered objects. And they will be printed on the output screen.

Separator(sep) Parameter:

This parameter is used to separate objects or values in the print statement. The default value is empty space(“ ”).

Example:

#program for sep parameter 
print(“Hi”, “I am Vijay”, sep=” “)
print(“Hi”, “I am Vijay”, sep=”—“)

Output:

Hi I am Vijay
Hi—I am Vijay

Explanation:

In the first print statement, given sep function and not initialised. So, the default space has been printed between two values.

In the second print statement, the given sep function is initialised by “—“.So, the output is printed like Hi—I am Vijay.

End Parameter:

If we have written two print statements, the second print statement will be printed in a new line. We can also specify what to print at the end using the end parameter.

It may be any characters, numbers, etc. The default value or character is “\n”.

Example 1:

#program without using end parameter in print() function
print(“Hello World”)
print(“I am Vijay”)

Output:

Hello World
I am Vijay

Example 2:

#program using end parameter in print() function
print(“Hello World”, end = ‘ ‘)
print(“I am Vijay”)

Output:

Hello World I am Vijay

Explanation:

As we can see from the above program output, it has printed in two lines, but we have printed the output in the same line using the end parameter by specifying the character as space.

We can also use the end parameter as:

Code:

#program for end parameter in print() function
print(“Hi all”, end = ‘@’)
print(“Good morning”)

Output:

Hi all@Good morning

Explanation:

In this program, instead of space, we have given a special character, “@.” And the first print statements end with the “@” character and the second stars after the “@” character.

File Parameter:

The program must contain an object with the write(string) method to use the file parameter. If we want to print the objects to the output screen, sys.stdout will be used.

Flush parameter:

This parameter is used for flushing the output screen. If it is true, otherwise, it will remain the same. It will remove the buffer from the program. It uses Boolean data type (True or false). The default value for this parameter is false.

Example: (Program for print() function using parameter)

X = “Vijay”
print(“X =”, X, sep = ‘@ ’, end = ‘20’)
print(“ X =”, X, end = ‘###’)

Output:

X =@Vijay 20 X =Vijay

Explanation:

First, we have initialised a string data ‘Vijay’ to a variable X. Then we have used the parameter sep(separator) with the character ‘@’. After that, we used the parameter end (the statement must be ended with the specified character) ‘20’. After 20, the next print statement will be printed, and it will be ended with ‘###’. The output will be as shown above.


Related Topics

Python MySQL Delete Operation

Python MySQL Delete Operation: Like the update operation where we were updating required field from a SQL table, we can also delete an entry from the table which we have...

4 minutes read.

Google Python Class

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

How to Practice Python Programming

Learning python kkis a step towards coding. Python gets one closer to programming languages. It is essential to practice every programming language to become a professional in coding. It is...

4 minutes read.

Python Network Programming

In network programming, python plays a very important role. Python provides full support for encoding and decoding data and network protocol in its standard library. Writing a network program in...

3 minutes read.

How to check data type in python

The data type represents the nature of a variable; it determines what kind of data it can store and what operations can be carried out on it. There are five...

4 minutes read.

Python maketrans() function

Introduction A static method is the string maketrans() one. It is used to make a one-to-one mapping between a string's character and its translation, i.e., to define the list of characters...

5 minutes read.

Static Variables in Python

What is a Static Variable? The variable that remains with a constant value throughout the program or throughout the class is known as a " Static Variable ". Static variables are...

3 minutes read.

Python String startswith() method

Python String startswith() method The string.startswith() method in Python returns a boolean value ‘True’ if the given string starts with the prefix, otherwise it returns False. Syntax startswith(prefix[, start[, end]]) Parameter prefix: This parameter signifies the value to check. start(optional):...

1 minute read.

Event Key in Python

Python Programming Language: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

CSV Write in Python

What is meant by CSV? CSV stands for Comma Separated Values. The name itself defines its purpose. CSV arranges the data in the form of tables and stores the organized data in...

3 minutes read.

Python Multithreading

In python, we can implement multithreading. In this tutorial, we will understand the basics of implementing multithreading in a python programming language. Multithreading is just like multiprocessing. We use it...

4 minutes read.

List in Python

What is List in Python In Python, lists are used to store the multiple values in one variable. We can say that list is the collection of similar as well as...

3 minutes read.

An Introduction to Subprocess in Python with Examples

Subprocess in Python By starting new processes, the Python function subprocess is utilized to run extra programs and applications. It makes it possible to run brand-new apps straight from a Programming...

6 minutes read.

Python float()

Python float() class The float() class in Python returns a floating point number constructed from a number or string x. Syntax class float([x]) Parameter x: This parameter represents a number or a string that can be converted...

1 minute read.

Sys Module in Python

What are Modules? The Modules are the kind of files that contain Python statements and definitions. The module is known by the name of the file followed by the suffix “.py”....

5 minutes read.

How to Make an App with Python

In this age of mobiles, rapid mobile application development has got a lot of traction. Moreover, app developers are high in demand because of the increase in digitization. Generally, Python is...

4 minutes read.

Tensorflow Angular in Python

TensorFlow is an open-source, Python-compatible toolkit for numerical computation that accelerates and simplifies the creation of neural networks and machine learning algorithms. They make the interesting notion that models can be...

6 minutes read.

Python Project Ideas

One of the most widely used programming languages today is Python. This pattern appears set to continue through 2023 and beyond. Therefore, working on some current Python project ideas is the...

10 minutes read.

Python Support

Python Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

GUI to Shut down, Restart and Logout from the PC using Tkinter in Python

GUI: One of the most significant factors that increased the usability of computer and digital technologies for common, less tech-savvy users is likely the development and widespread adoption of GUIs. GUIs...

4 minutes read.