×

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 Pascal Triangle

Python Pascal Triangle Pascal triangle A pascal triangle is a number pattern of triangular array of the binomial coefficients. For designing a pascal triangle, we write a function in the program which...

5 minutes read.

SKLearn Model Selection

The model selections of SK learn has many functions with which we can work on.It has functions to cross-validate the model and, it also provides validation and learning curves.It is...

3 minutes read.

Python input() function

Python input() function The input() function in Python reads a line from input and converts it to a string (stripping a trailing newline). Syntax input([prompt]) Parameter prompt: This function represents a string, depicting a default...

1 minute read.

Anaconda in Python 3

What is Anaconda in Python 3? Anaconda is an open-source package combining Python and R programming languages used for data analytics and processing data. It consists of a huge number of...

4 minutes read.

Python Set Methods

[et_pb_section][et_pb_row][et_pb_column type="4_4"][et_pb_text] Python Set Methods A set is a collection which is unordered and unindexed. Python has a set of built-in methods that you can use on sets. Methods ...

4 minutes 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.

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.

Nested Tuple in Python

If you are a Python learner, this page contains all the information that helps you know about nested tuple and how to access it in python. What is a Tuple? Multiple items...

4 minutes read.

What is the Python Global Interpreter Lock?

Introduction When working with processes, Python employs a form of process lock called the Global Interpreter Lock (GIL). Python typically executes a collection of typed statements using just one thread. It...

4 minutes read.

List Comprehension in Python3

List A list in python is a complex data type, and a list is a collection of the number of data. The data variable may or may not be of the...

5 minutes read.

Imread Python

In this walkthrough, we'll go over the specifics of using the imread() method of OpenCV-Python and various methods for loading images. Imread is an Image reading library. One of the most helpful...

7 minutes read.

Python for Loop Increment

Introduction In general, loops are employed for sequential traversal. It belongs to the definite iteration category. Definite iterations imply that the number of iterations is explicitly set in advance.  In this article,...

4 minutes read.

Python min() function

Python min() function returns you the minimum value element in an iterable. We can also use this function to determine the smallest value among various arguments passed to this function. We...

4 minutes read.

Python program to print array element present at even position

Python program to print array element present at even position In this program, we'll see a Python program that prints the elements of an array that are in even positions. We...

1 minute read.

Python setattr() function

Python setattr() function The setattr() function sets the value of the specified attribute of the specified object. Syntax setattr(object, name, value) Parameter object: This parameter represents any object. name: This parameter represents the name of the attribute you...

1 minute read.

Python sklearn train_test_split

Sklearn: One of the most beneficial open-source libraries for learning algorithms in Python is, without a doubt, Sklearn or Scikit-Learn. The most effective tools for statistical modeling and machine learning are all included in...

6 minutes read.

Python Program to Check Leap Year

Python Program to Check Leap Year Leap year: We all know that each year has 365 or 366 days. But whenever a year has 366 days, then the year is said...

2 minutes read.

Check Palindrome in Python

Python is an object-oriented high-level programming language. Python has dynamic semantics and has high-level built-in data structures which support dynamic typing and dynamic binding. Python provides rapid development. It has...

4 minutes read.

Python Program to Generate a Random String

The term "random" refers to a group of information or data that can be accessed in any chronological order. To create random strings, a Python program called random is utilized....

6 minutes read.

Python Struct

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.