0

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)
martineau
  • 119,623
  • 25
  • 170
  • 301

2 Answers2

1

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

martineau
  • 119,623
  • 25
  • 170
  • 301
Hemesh
  • 107
  • 9
0

You do not need a for loop for this, tuple unpacking is listed under the Tuples and Sequences section in the official Python documentation.

In [11]: A = 'aca'

In [12]: a, b, c = A.partition('c')

In [13]: a
Out[13]: 'a'

In [14]: b
Out[14]: 'c'

In [15]: c
Out[15]: 'a'
yudhiesh
  • 6,383
  • 3
  • 16
  • 49