[Python] Be careful when using print

When using print with Python3, you should be aware of the sep and end options in the corner of your head. It's a very basic thing, but if you forget it, you may get unintended results.

s = 'abc'
t = 'def'

#Spaces before and after commas and tabs
print(s, ',', t) # -> abc , def
print(s, '¥t', t) # -> abc ¥t def

#If you don't want to put spaces before and after commas and tabs, specify an empty string for sep.
print(s, ',', t, sep='') # -> abc,def
print(s, '¥t', t, sep='') # -> abc¥tdef

#If you do not want to start a new line, specify an empty string for end
print(s, ',', t, sep='', end='') # -> abc,def (no line breaks)
print(s, '¥t', t, sep='', end='') # ->abc \ tdef (no line breaks)

Recommended Posts

[Python] Be careful when using print
Causes when python version cannot be changed using pyenv
Precautions when using pit in Python
(Note) Be careful with python argparse
Note links that may be useful when using Python, Selenium2
Scripts that can be used when using bottle in Python
Precautions when using phantomjs from python
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
[VS Code] ~ Tips when using python ~
When using regular expressions in Python
Be careful when specifying the default argument value in Python3 series
Be careful of LANG for UnicodeEncodeError when printing Japanese with Python 3
[python, multiprocessing] Behavior for exceptions when using multiprocessing
Be careful when adding an array to an array
Be careful when running CakePHP3 with PHP7.2
Start using Python
[Python memo] Be careful when creating a two-dimensional array (list of lists)
Scraping using Python
"Temporary solution" when pip cannot be updated [Python]
Character encoding when using csv module of python 2.7.3
Be careful when working with gzip-compressed text files
What are you using when testing with Python?
Python note: When the pip command cannot be used
Operate Redmine using Python Redmine
Summary when using Fabric
Fibonacci sequence using Python
Data analysis using Python 0
Initial settings when using the foursquare API in python
Be careful when differentiating the eigenvectors of a matrix
Be careful when reading data with pandas (specify dtype)
Error due to conflict between python when using gurobi
Check types_map when using mimetypes on AWS Lambda (Python)
Installation method when using RealSense from Python (pyenv edition)
Using Python #external packages
Python print function (sequel)
WiringPi-SPI communication using Python
Age calculation using python
Troublesome story when using Python3 with VScode on ubuntu
How to exit when using Python in Terminal (Mac)
Error when executing Python commands without using Anaconda Prompt
Search Twitter using Python
Name identification using python
Notes using Python subprocesses
Precautions when using Chainer
Minimum memo when using Python on Mac (pyenv edition)
Try using Tweepy [Python2.7]
What I was addicted to when using Python tornado
Minimum notes when using Python on Mac (Homebrew edition)
[Python3] Be careful with removing character strings (strip, lstrip, rstrip)
Solution when the image cannot be displayed with tkinter [python]
[Python] Variadic arguments can be used when unpacking iterable elements
Master the type in Python? (When should type check be done)
A memo when creating a directed graph using Graphviz in Python
Be careful when assigning Series as a column to pandas.DataFrame
Solve the Japanese problem when using the CSV module in Python.
Things to keep in mind when using Python with AtCoder
Precautions that must be understood when building a PYTHON environment
Things to keep in mind when using cgi with python.
[Python] When are variables created? When will class instances be erased?
List of libraries to install when installing Python using Pyenv