[Tutor] Re:Help on Tutor
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Mon Jul 28 13:22:01 2003
On Mon, 28 Jul 2003, Scott Widney wrote:
> ## Yep. So I'll have to deal with that.
> ## The easiest way would be to just get rid of the fractional part
> >>> int(time.time())
> 1059404248
> ## And it would be much easier to get the last two digits
> ## if I was dealing with a string.
> >>> str(int(time.time()))
> '1059404275'
> ## Great! Now I just need the last two characters.
> >>> str(int(time.time()))[-2:]
> '89'
Hi Scott,
An alternative way of doing this, without as much string manipulation, can
be to use the "modulo" (remainder) operator. Anything divided by 100 will
leave a remainder between 0 and 99.
###
>>> int(time.time()) % 100
16
###
Hope this helps!