@djangoproject · Post #208 · 12/17/2016, 08:19 AM
http://pythoncentral.io/cutting-and-slicing-strings-in-python/ Python strings as sequences of #characters Python strings are sequences of individual characters, and share their basic methods of access with those other Python sequences – #lists and #tuples. s = 'Don Quijote' »> s[4😏 'Quijote' # Returns from pos 4 to the end of the string »> s[:4] 'Don ' # Returns from the beginning to pos 3 »> s[4:8:1] # 1 is the default value anyway, so same result 'Quij' »> s[4:8:2] # Return a character, then move forward 2 positions, etc. 'Qi' # Quite interesting! »> s.split() ['Don', 'Quijote'] »> tim = '16:30:10' »> hrs, mins, secs = tim.split(':') »> hrs '16' »> mins '30' »> secs '10' »> tim.split(':', 1) # split() only once ['16', '30:10'] »> tim.rsplit(':', 1) ['16:30', '10'] . . .
Hashtags