python 資料型別 python 做一天內時間段判斷測試

zhenggaona1發表於2018-10-09

[root@dba-test hexinyunwei]# python

Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) 

[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import time

>>> t = time.localtime(time.time())

>>> ti = '%d' % (t.tm_hour*60+t.tm_min)

>>> print ti

652

>>> if ti <= 655:

...  print 'ok'

... 

>>> tim = ti = '%d' % 653

>>> tim = '%d' % 653

>>> print tim

653

>>> print ti

653

>>> ti = '%d' % (t.tm_hour*60+t.tm_min)

>>> print ti

652

>>> if ti <= tim:

...  print 'ok'

... 

ok

>>> if ti >= 655:

...  print 'ok'

... 

ok

>>> if 3 < 2:

...  print 'ok'

... 

>>> if 3 < 4:

...  print 'ok'

... 

ok

>>> 

說明python 預設數字是大於字元竄的,最好同型別進行比較

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23944170/viewspace-2215650/,如需轉載,請註明出處,否則將追究法律責任。

相關文章