在python中打印并加入语句 [英] Print and join statement in python
本文介绍了在python中打印并加入语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是python的新手.我有一个序列,可以使用join
方法打印它,并且可以分别打印序列的长度.我无法同时打印两者.我到目前为止是:
I am newbie to python. I have a sequence and I am able to print it using join
method and able to print the length of the sequence separately. I am not able to print both together. What I so far is:
>>> str = "-";
>>> seq = ("a", "b", "c");
>>> print str.join( seq );
a-b-c
>>> print len(seq)
3
我想同时打印str.join(seq)
和len(seq)
并同时打印一些lines
(我想要的输出):
I want to print both the str.join(seq)
and len(seq)
together in one line, with some lines
like this (My desired output):
The join output is: a-b-c The length is: 3
所有这些都在一行中. python
有可能吗?
All of this in one line. Is it possible in python
?
推荐答案
seq = ('a', 'b', 'c')
joined = '-'.join(seq)
print('The join output is:', joined, 'The length is:', len(seq))
或
print('The join output is: ' + joined + ' The length is: ' + str(len(seq)))
这篇关于在python中打印并加入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文