True/False formats as 1/0 in a fixed width string

Discussion in 'Python' started by Frank Millman, Mar 27, 2013.

  1. Hi all

    This is a bit of trivia, really, as I don't need a solution.

    But someone might need it one day, so it is worth mentioning.

    >>> '{}'.format(True)

    'True'
    >>> '{:<10}'.format(True)

    '1 '

    One might want to format True/False in a fixed width string, but it
    returns 1/0 instead. Is there any way to make this work?

    Frank Millman
     
    Frank Millman, Mar 27, 2013
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    1,307
    Toby Inkster
    Jan 28, 2005
  2. johnp
    Replies:
    4
    Views:
    3,955
    Toby Inkster
    May 23, 2005
  3. Siemel Naran

    Does true ^ true return false?

    Siemel Naran, Jun 17, 2004, in forum: C++
    Replies:
    19
    Views:
    942
    Chris Theis
    Jun 18, 2004
  4. Pierre Quentel

    "0 in [True,False]" returns True

    Pierre Quentel, Dec 12, 2005, in forum: Python
    Replies:
    59
    Views:
    1,500
    Grant Edwards
    Dec 16, 2005
  5. André
    Replies:
    3
    Views:
    1,955
  6. ssk
    Replies:
    5
    Views:
    6,323
    Jukka K. Korpela
    Oct 30, 2006
  7. bdb112
    Replies:
    45
    Views:
    1,895
    jazbees
    Apr 29, 2009
  8. Shea Martin

    false or true == true .... WTF?

    Shea Martin, Apr 5, 2007, in forum: Ruby
    Replies:
    4
    Views:
    309
    Bertram Scharpf
    Apr 5, 2007
Loading...