Python str split function

Python str split function has a second argument maxsplit. If maxsplit is n, it splits it into n+1 parts.

name = "firstname middlename last big biggername"

first, middle, last = name.split(" ", 2)

Output

print(first) # firstname
print(middle) # middlename
print(last) # last big biggername

Other articles with the same tag

  • Python For Rubyists
  • Python datetime snippets
  • Debugging Flask app with pdb
  • Python tidbits
  • Back