[Python] Display list elements with variadic arguments

There are many ways to display all list elements in Python, but the easiest way is to use variadic arguments if you just want to display them without any processing.

The following source code is supposed to be executed in Python 3

Show all list elements

Source code example

words = ["new", "Rice", "President"]
print(*words)

Output result

New US President

By default, it is output separated by spaces, and a line break is performed at the end.

Display separated by commas

By specifying sep for print, it can be separated by any character. If you do not need a delimiter, specify an empty string.

Source code example

words = ["new", "Rice", "President"]
print(*words, sep=",")

Output result

new,Rice,President

Display without delimiter

Source code example

words = ["new", "Rice", "President"]
print(*words, sep="")

Output result

New President

Recommended Posts

[Python] Display list elements with variadic arguments
Initialize list with python
[python] How to display list elements side by side
Getting list elements in Python
[Python] Variadic arguments can be used when unpacking iterable elements
Get Python list elements with multiple indexes (number) Simple method
Convert list to DataFrame with python
Delete multiple elements in python list
[Python] Display only the elements of the list side by side [Vertical, horizontal]
[Python] list
[Python] Calendar-style heat map (with holiday display)
Calculate and display standard weight with python
Display a list of alphabets in Python 3
Display Python 3 in the browser with MAMP
Excel aggregation with Python pandas Part 2 Variadic
How to display python Japanese with lolipop
FizzBuzz with Python3
Python basics: list
Scraping with Python
[python] Check the elements of the list all, any
Statistics with python
Scraping with Python
Python with Go
Interactively display algebraic curves with Python and Jupyter
Twilio with Python
Python> Run with run-time arguments> Use import argparse
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Python> Comprehension / Comprehension> List comprehension
Bingo with python
Zundokokiyoshi with python
A simple to-do list created with Python + Django
Randomly select elements from list (array) in python
Sort list elements in a specified order in Python
Python list manipulation
Excel with Python
[Python] Manipulating elements in a list (array) [Sort]
Microcomputer with Python
Convert strings to character-by-character list format with python
How to remove duplicate elements in Python3 list
Cast with python
[Python] Manipulation of elements in list (array) [Add / Delete]
It's too troublesome to display Japanese with Vim's python3.
Display and shoot webcam video with Python Kivy [GUI]
[Python] Outputs all combinations of elements in the list
Group by consecutive elements of a list in Python
Python> function> Docstrings> Description to display with help () / .__ doc__
Display USB camera video with Python OpenCV with Raspberry Pi
Serial communication with Python
Sorted list in Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Python Exercise 2 --List Comprehension
Socket communication with Python
Data analysis with python 2
List of python modules