I think that there are many cases where the output method is limited due to online programming learning, skill check, etc. Even though I got the answer, sometimes I couldn't output it as I expected, so I summarized what I investigated.
[Method 1] Put print () in the list comprehension
ex.py
L = ["a","b","c","d"]
[print(i) for i in L]
[Method 2] Slice the character string character by character and insert print ().
ex.py
L = ["a","b","c","d"]
for i in L[0:]:
print(i)
In any case, the execution result will be as follows.
a b c d
ex.py
L = ["a","b","c","d"]
L=' '.join(L)
print(L)
The execution result will be as follows
a b c d
With ','. join
a,b,c,d
The element in'' before .join () can be set freely so that
You can output without using .join ().
ex.py
L = [['a', 'b', 'c', 'd']]
print(*L[0])
Execution result
a b c d
ex.py
L_int = [1, 2, 3, 4]
L=[str(a) for a in L_int]
L=" ".join(L)
print(L)
The execution result will be as follows
1 2 3 4
I would be grateful if you could tell me if there is any method other than those described this time.
Recommended Posts