小编kut*_*edk的帖子

有没有更好的方法来检查单词的第一个位置的元音?

我正在尝试检查元音作为单词的第一个字符.对于我的代码我目前有这个:

if first == 'a' or first == 'e' or first == 'i' or first == 'o' or first == 'u':
Run Code Online (Sandbox Code Playgroud)

我想知道有更好的方法来做这个检查还是这是最好和最有效的方式?

python string python-2.7

7
推荐指数
2
解决办法
235
查看次数

如何让 python 在函数运行时打印出当前经过的时间?

所以我目前有 python 打印函数运行完成后需要多长时间,例如:

import time
t = time.time()
# do something in here
print "\n Time Taken: %.3f sec" % (time.time()-t)
Run Code Online (Sandbox Code Playgroud)

但我想显示自函数启动以来已经过去的生存时间,但我不太想出一种方法来实现这一点。

例如在终端中我希望它说这样的话:

Working on xFunction. Time Elapsed 72.485 sec... (live updated time)
xFunction Has finished.
Time Taken: 1152.546 sec
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。

python

4
推荐指数
1
解决办法
2270
查看次数

标签 统计

python ×2

python-2.7 ×1

string ×1