Home > Software engineering >  Print list without brackets using f string
Print list without brackets using f string

Time:11-21

Title says it all. I have a list with some values and I want to print them so that the brackets don't show up. I know I can use print(*value) but that doesn't work when using f-strings. To illustrate my point:

print(f'This list contains: {function_that_returns_list()}')

I've been looking for an answer for hours so any help is greatly appreciated.

CodePudding user response:

Try this:

print(f'This list contains: {" ".join(function_that_returns_list())}')

CodePudding user response:

Why not just chop off the first and last character in the str result, representing the start and close brackets? Brief example below:

L = ['1', '2', '3']

print(f'This list contains: {str(L)[1:-1]}')

Out:

This list contains: '1', '2', '3'
  • Related