python
Use separator in print() method of python
While printing values using the print() method in python we can pass a separator which will be added between values passed inside print() methid.
first_name = "Rick"
last_name = "Grimes"
print("My", "name", "is", first_name, last_name, sep=" ")
# -> My name is Rick Grimes
print("My", "name", "is", first_name, last_name, sep=":")
# -> My:name:is:Rick:Grimes
In the code snippet, we are printing different values and passing separator using sep="" syntax. In the first example, we are printing values with a space separator and in the second example we are using separator ":".
Was this helpful?
Similar Posts
- [Python] Use json.dumps() to pretty-print Python dicts
- Print whole month from calendar using python
- [Python] The get() method on Python dicts and its "default" arg
- Print DataFrame in pretty format in Terminal
- Get string length using len() method python
- Use of else condition with for loop in Python
- Use of try, except, else and finally in python