Search code examples
pythonpython-3.xiterable-unpacking

Problem with str.partition() and tuple unpacking


I am using partition in strings and am trying to use tuple unpacking on them but it's returning the error expected 3 got 1. So here's my code. Please explain where I went wrong.

a='aca'
for a,b,c in a.partition('c'):
print(a)

Solution

  • You are using the same variable twice (a) and no need to use a loop just write a,b,c = String_name.partition('c').