Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:34:48+00:00 2026-06-02T22:34:48+00:00

I am puzzled why I can assign/unpack the return of split() to the appropriate

  • 0

I am puzzled why I can assign/unpack the return of split() to the
appropriate number of variables, but the same fails for use in a
print string using formatting directives.

E.g., given:

In [202]: s
Out[202]: 'here are 4 values'

In [203]: s.split()
Out[203]: ['here', 'are', '4', 'values']

This works as expected:

In [204]: a, b, c, d = s.split()

In [205]: print '%s %s %s %s' % (a, b, c, d)
here are 4 values

But this fails ..

 In [206]: print '%s %s %s %s' % (s.split())

I am not sure why? Shouldn’t the return of split() be
unpacked and be distributed over the expected arguments for the
formatting strings?

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\bla\Desktop\<ipython-input-206-600f130ff0b2> in <module>()
----> 1 print '%s %s %s %s' % (s.split())

TypeError: not enough arguments for format string

“Note enough arguments” .. I do have the right number of items in the list. Does the list for some reason not unpack in this case, but does with assignments to variables?

I came across this in attempting to answer this question
writing column entry just one below another in python

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:34:50+00:00Added an answer on June 2, 2026 at 10:34 pm

    You must convert s.split() into a tuple like so

    >>> s = 'here are 4 values'
    >>> '%s %s %s %s' % tuple(s.split())
    'here are 4 values'
    

    for formatting or use .format() instead, unpacking the arguments.

    '{0} {1} {2} {3}'.format(*s.split())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm puzzled about the correct use of bind variables with dates in Oracle. This
I am puzzled. I can write this: import Control.Monad main = print $ head
I'm really puzzled by this one!! I'm sure it's simple but really can't figure
I've been reading on this quite some time...and i'm puzzled - Can you help
I am a little bit puzzled as to how I can optimize my program
I've looked around and have bits and pieces but can't put the puzzle together.
I am puzzled why this return false doesn't cancel the post-back. function validate() {
I know 'this' can be a problem when you don't understand Javascript well but
This question has puzzled me for a while. A public property that can be
I am puzzled with the statement that IE does not support <q> tag but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.