1

I was recently started to learn one more programming language, Python. but I stuck with one problem in chapter String formating.

My question as we include integers, floating numbers, variables etc. in string by symbols like %c or %d, is there is a way to include list directly without splitting in numbers of variables?

foo = [1, 3, "this is str."]#list
print("The massage is '%SOMETHING ' ", foo)
1
  • 1
    %s works for anything. Commented Apr 1, 2020 at 10:45

3 Answers 3

2

You can use f-string on python 3.6+.

Just use


v_list = [3.6, 'as', 4]
print(f'Showing {v_list}')
Sign up to request clarification or add additional context in comments.

Comments

1

In Python, you can insert lists into strings with the format string method like the following: 1) print("The message is {}".format(list)) or 2) print("The message is {ls}".format(ls=list))

Comments

0

You can conver the list to a string using str():

foo = [1, 2,' this is str']
print("This is your list: '", str(foo), "' and its great!")

The out put will be:

This is your list: '[1, 2,' this is str']' and its great!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.