When the list is [0, 0, 0, 0, 0, 0, 0, 0], Output value is
0 0 0 0
0 0 0 0
It's a situation where it has to come out as. I know how to print out each element, but I don't know how to tie it up as much as I want, leave a few pieces per line, and change the lines. How can I change the line?
python list
Learn about list slices and join. If you search, you'll find a lot of explanations.
a = list(range(100))
b = 'adsf'.join(map(str, a[30:80:4]))
print(b)
>> 30adsf34adsf38adsf42adsf46adsf50adsf54adsf58adsf62adsf66adsf70adsf74adsf78
a = list(range(100))
b = '\n'.join(map(str, a[30:40:2]))
print(b)
>> 30
32
34
36
38
It's not hard at all! Try it yourself.
© 2024 OneMinuteCode. All rights reserved.