菠萝红椒

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

小笔记 - python

1,查找列表中某个值的位置(python)

p=list.index(value)               list为列表的名字             value为查找的值  p为value在list的位置

2,正则-移除字符串两侧空格

re.sub(' ', '', attrValueString)

3,正则-字符串转列表

attrValue = “1.0, 2.2, 3, 5.04”

re.findall('[a-z.0-9]+', attrValue)

4,转换秒到时间格式。

1 def convertseconds(self, seconds) :
2     m, s = divmod( int(seconds), 60)
3     h, m = divmod(m, 60)
4     formatsecond = "%d:%02d:%02d"%(h, m, s)
5     return formatsecond

 

posted on 2020-12-17 12:05  菠萝红椒  阅读(70)  评论(0)    收藏  举报