Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在str中使用%包含列表?python问题_Python_Python 3.x_String_List_Printing - Fatal编程技术网

如何在str中使用%包含列表?python问题

如何在str中使用%包含列表?python问题,python,python-3.x,string,list,printing,Python,Python 3.x,String,List,Printing,我最近开始学习另一种编程语言Python。但我在章节字符串格式方面遇到了一个问题 我的问题是,当我们通过符号%c或%d在字符串中包含整数、浮点数、变量等时,是否有一种方法可以直接包含列表而不拆分变量数 foo=[1,3,这是str.]list 打印按摩是“%SOMETHING”,foo 您可以在python 3.6+上使用 只用 v_列表=[3.6,'as',4] printf'Showing{v_list}' 您可以在python 3.6+上使用 只用 v_列表=[3.6,'as',4] pr

我最近开始学习另一种编程语言Python。但我在章节字符串格式方面遇到了一个问题

我的问题是,当我们通过符号%c或%d在字符串中包含整数、浮点数、变量等时,是否有一种方法可以直接包含列表而不拆分变量数

foo=[1,3,这是str.]list 打印按摩是“%SOMETHING”,foo 您可以在python 3.6+上使用

只用

v_列表=[3.6,'as',4] printf'Showing{v_list}' 您可以在python 3.6+上使用

只用

v_列表=[3.6,'as',4] printf'Showing{v_list}'
在Python中,可以使用如下格式字符串方法将列表插入字符串: 1打印消息为{}.formatlist 或
2打印消息为{ls}.formatls=list

在Python中,可以使用如下格式字符串方法将列表插入字符串: 1打印消息为{}.formatlist 或
2打印消息为{ls}。formatls=list

您可以使用str将列表转换为字符串:

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

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

可以使用str将列表转换为字符串:

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

This is your list: '[1, 2,' this is str']' and its great!
%s对任何东西都有效。%s对任何东西都有效。