简体   繁体   English

python2.7打印列表中的值

[英]python2.7 print values in list

I have a question to print values in list. 我有一个问题要打印列表中的值。

import time
strings = time.strftime("%Y,%m,%d")
t = strings.split(',')
date = [int(x) for x in t]
print date

then result is 那么结果是

[2016,5,15]

But I want to print values in date like this 但是我想在这样的日期中打印值

20160515

How can I fix it? 我该如何解决?

What's wrong with doing it like this: 这样做有什么问题:

>>> strings = time.strftime("%Y%m%d")
>>> strings
'20160515'

Why don't just do: 为什么不只是做:

time.strftime("%Y%m%d")

On the other hand, if you are just looking for a way to concatenate elements of a list, use join : 另一方面,如果您只是在寻找一种连接列表元素的方法,请使用join

In [110]: s = time.strftime("%Y,%m,%d")

In [111]: sl = s.split(',')

In [112]: ''.join(sl)
Out[112]: '20160515'

you must just change your code : 您只需更改代码即可:

import time
strings = time.strftime("%Y%m%d") # delete ','
print strings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM