如何在一行中打印出字符串和列表-Python [英] how to print out a string and list in one line-python

查看:53
本文介绍了如何在一行中打印出字符串和列表-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

a=[1,2,3]
print "the list is :%"%(a)

我想这样打印一行:列表是:[1,2,3] 我无法在一线之内完成它,而我必须这样做:

I want to print out one line like this: the list is:[1,2,3] I can not make it within one line and I have to do in this way:

print " the list is :%"
print a

我想知道我是否可以打印出一些与字符串格式和单行列表相结合的内容.

I am wondering whether I can print out something that combine with string formatting and a list in ONE line.

推荐答案

最简单的方法是CodeHard_or_HardCode在注释中所说的.对于Python 3,它将是:

The simplest way is what CodeHard_or_HardCode said in the comments. For Python 3 it would be:

a=[1,2,3]
print('This is a list', a)

This is a list [1, 2, 3]

这篇关于如何在一行中打印出字符串和列表-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆