×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

sep parameter in Python with print() function

By IncludeHelp Last updated : December 08, 2024

The 'sep' parameter in printf() function

sep parameter stands for separator, it uses with the print() function to specify the separator between the arguments.

The default value is space i.e. if we don't use sep parameter – then the value of the arguments is separated by the space. With the "sep", we can use any character, an integer or a string.

Note: "sep" is available in Python 3.x or later versions.

Syntax

print(argument1, argument2, ..., sep = value)

Examples

Example 1: Using different values for sep parameter

# variables
name = "Mike"
age = 21
city = "Washington, D.C."

# printing without using sep parameter
print("Without using sep parameter...")
print(name, age, city)
print()

# printing with using sep parameter
# separated by spaces
print("With using sep parameter (separated by spaces)")
print(name, age, city, sep=' ')
print()

# printing with using sep parameter
# separated by colon (:)
print("With using sep parameter (separated by colon)")
print(name, age, city, sep=':')
print()

# printing with using sep parameter
# separated by " -> "
print("With using sep parameter (separated by ' -> ')")
print(name, age, city, sep=' -> ')
print()

Output

Without using sep parameter...
Mike 21 Washington, D.C.

With using sep parameter (separated by spaces)
Mike 21 Washington, D.C.

With using sep parameter (separated by colon)
Mike:21:Washington, D.C.

With using sep parameter (separated by ' -> ')
Mike -> 21 -> Washington, D.C.

Example 2: Disable space separator, and using numbers/characters for sep values

# variables
name = "Mike"
age = 21
city = "Washington, D.C."

# printing with using sep parameter
# disable space separator 
print("With using sep parameter (disable space separator)")
print(name, age, city, sep='')
print()

# printing with using sep parameter
# separated by number
print("With using sep parameter (separated by number)")
print(name, age, city, sep='12345')
print()

# printing with using sep parameter
# separated by " ### "
print("With using sep parameter (separated by ' ### ')")
print(name, age, city, sep=' ### ')
print()

Output

With using sep parameter (disable space separator)
Mike21Washington, D.C.

With using sep parameter (separated by number)
Mike123452112345Washington, D.C.

With using sep parameter (separated by ' ### ')
Mike ### 21 ### Washington, D.C.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.