|
Post by spohnz on Jun 8, 2017 13:26:42 GMT -6
We were talking in the game today about slicing strings to get a return you want. So I will demonstrate what I mean here. Lets say that you need the time for a log file and nothing more, no month, day or year. How would you do it?
>>>import time >>>time.ctime()
'Thu Jun 8 14:20:36 2017' But all I want is the 14:20:36 part and nothing more. Well slicing is able to grab just what you want from a string. [0:1] the first digit is the starting character in the string. the second digit is the stopping character int he string.
>>> t=time.ctime()
>>> len(t)
24
>>> t[3:14]
' Jun 8 14:'
>>> t[12:16]
'4:23'
>>> t[11:19]
'14:23:12'
>>> So I did a couple of times to demonstrate how I normally zero in on my slices. the len(t) didn't have to be in there but wanted to show how I would get the length if needed.
|
|