2014-04-06 10:11:15 +00:00
|
|
|
# default separator (whitespace)
|
2014-01-21 03:00:21 +00:00
|
|
|
print("a b".split())
|
|
|
|
print(" a b ".split(None))
|
|
|
|
print(" a b ".split(None, 1))
|
|
|
|
print(" a b ".split(None, 2))
|
|
|
|
print(" a b c ".split(None, 1))
|
|
|
|
print(" a b c ".split(None, 0))
|
|
|
|
print(" a b c ".split(None, -1))
|
2015-04-11 21:17:16 +00:00
|
|
|
print("foo\n\t\x07\v\nbar".split())
|
|
|
|
print("foo\nbar\n".split())
|
2014-04-06 10:11:15 +00:00
|
|
|
|
|
|
|
# empty separator should fail
|
|
|
|
try:
|
|
|
|
"abc".split('')
|
|
|
|
except ValueError:
|
|
|
|
print("ValueError")
|
|
|
|
|
|
|
|
# non-empty separator
|
|
|
|
print("abc".split("a"))
|
|
|
|
print("abc".split("b"))
|
|
|
|
print("abc".split("c"))
|
|
|
|
print("abc".split("z"))
|
|
|
|
print("abc".split("ab"))
|
|
|
|
print("abc".split("bc"))
|
|
|
|
print("abc".split("abc"))
|
|
|
|
print("abc".split("abcd"))
|
|
|
|
print("abcabc".split("bc"))
|
|
|
|
print("abcabc".split("bc", 0))
|
|
|
|
print("abcabc".split("bc", 1))
|
|
|
|
print("abcabc".split("bc", 2))
|
2014-05-11 18:17:28 +00:00
|
|
|
|
|
|
|
print(b"abcabc".split(b"bc", 2))
|