Jan-12-2020, 11:15 PM
Quote:if I enter say 10 in this case the string it will be .split () will be output to '1' and '0'That's not how split works.
split requires a delimiter. If none is supplied space is assumed.
the results of a split are returned in a list
remember, the best way to learn is to try.
bring up the python interpreter so you can try for yourself (just type python3 at command line)
some examples:
example 1, no delimiter specified, so default space is used
>>> string1 = "This is a string" >>> string1.split() ['This', 'is', 'a', 'string']example 2 specifing a delimiter:
>>> string2 = "This string has a hyphenated-word in it" >>> string2.split("-") ['This string has a hyphenated', 'word in it'] >>>useful for separating items delimited with special characters:
example3:
>>> data = "10/18/2016|ALA|16|970|827|540|2337" >>> dlist = data.split('|') >>> dlist ['10/18/2016', 'ALA', '16', '970', '827', '540', '2337'] >>>