×

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

Notepad++ For Python

In this article, you are going to learn what notepad++ is and how it is integrated with python to use the python programming language. You can also learn how to...

4 minutes read.

How to upgrade PIP in python

We use the PIP command in our command prompt to install any package. PIP is used to install published Python packages in the PyPI (Python package index) or other indices....

3 minutes read.

Python Word Tokenizer

Python Overview Python is an Object-Oriented high-level language. Python is designed to be highly beginner-friendly. Python has an English-like syntax, which is very easy to read. Python is an interpreted language...

4 minutes read.

Best Database in Python

In this tutorial, Firstly, we will understand what the term database means. Further, we will see the various databases supported in Python and when to use which one. Further, we...

7 minutes read.

BOTTLE Python Web Framework

The Bottle is a lightweight WSGI micro web framework for python. It acts like a thin wrapper around a web server where it is distributed as a single file module...

4 minutes read.

Arithmetic Expressions in Python

What is Python Expression? Expressions are collections of operands and operators. Python expressions are translated by the Python interpreter into some value or outcome. In Python, an expression is made up...

13 minutes read.

What is Sleeping Time in Python

Did you ever postpone a Python program's execution? Usually, you want your code to execute as quickly as possible. But there are times when it is in your best interests...

3 minutes read.

Classes & Objects in Python

Classes and Objects are used in most modern programming languages, mainly in Object-oriented Programming languages. What is meant by Object Oriented Programming language? Usage of objects and their components in order to...

7 minutes read.

Covariance in Python

Covariance is defined as the estimate of the difference of change between two variables or more variables. It defines the changes of two variables together. In Python, The covariance can...

2 minutes read.

Python range() function

Python range() function The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. Syntax range(stop)        or range(start, stop[, step]) Parameter start: It is...

1 minute read.

Python | a += b is not always a = a + b

a += b in Python doesn't always behave the same way as a = a + b; the same operands can produce different outcomes depending on the circumstances. But we...

3 minutes read.

How to Install Tweepy in Python

In this article, we will learn or understand how to install Tweepy in Python and what Tweepy is. Firstly, let’s understand What Tweepy is. As we all know, one of the...

3 minutes read.

Python List remove() method

Python List remove() method The list.remove () method in Python removes the item at the specified position in the given list. Syntax list.remove(x) Parameter x: This parameter represents the element you want to remove and accepts any type...

1 minute read.

Shallow Copy and Deep Copy in Python

Shallow Copy and Deep Copy in Python In this section, we will learn about the Shallow Copy and Deep Copy in the Python program. But before going through the topic, we...

6 minutes read.

Accessing Key-value in Dictionary in Python

A Python word reference is an assortment of key-esteem matches where each key is related to worth. Worth in the key-esteem pair can be a number, a string, a rundown,...

5 minutes read.

Difference between Yield and Return in Python

Python yield statement The generators are defined by using the yield statement in Python. Generally, it converts a normal Python function into a generator.  The yield statement hauls the function and returns...

3 minutes read.

Python Logistic Regression with Sklearn & Scikit

In this article, we'll walk through a tutorial for utilising the Python Sklearn (formerly known as Scikit Learn) package to implement logistic regression. To assist you in remembering the concept,...

18 minutes read.

Python Data Structures

Python Data Structures: Python is a programming language used worldwide for various fields such as building dynamic websites, artificial intelligence and many more. However, there is data that plays a...

18 minutes read.

How to import numy in python

How to Install NumPy in Python Python is a vast ocean of libraries, modules, and different functions. It has a solution for almost everything. Using Python, we can simplify even a...

3 minutes read.

Python Program to Print Sum of all Elements in an Array

Python program to print sum of all elements in an array A set of objects stored in contiguous memory locations is referred to as an array. The concept is to keep...

2 minutes read.