Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understood you right, you could do it this way:</p> <pre><code>a = 0b0010111010 '{:010b}'.format(a) #The output is: '0010111010' </code></pre> <p><em>Python 2.7</em></p> <p>It uses string <a href="http://docs.python.org/release/2.7/library/string.html#format-specification-mini-language" rel="nofollow"><code>format</code> method</a>.</p> <p>This is the answer if you want to represent the binary string with leading zeros.</p> <p>If you are just trying to generate a random string with a binary you could do it this way:</p> <pre><code>from random import choice ''.join(choice(('0','1')) for _ in range(10)) </code></pre> <h1>Update</h1> <p>Unswering your update. I made a code which has a different output if compared to yours:</p> <pre><code>from random import choice from pprint import pprint arr = [] def create_string(x): for i in xrange(10): # 10 random populations arr.append([]) for j in xrange(x): # population size v = ''.join(choice(('0','1')) for _ in range(10)) arr[-1].append(v) return arr a = create_string(5) pprint(a) </code></pre> <p>The output is:</p> <pre><code>[['1011010000', '1001000010', '0110101100', '0101110111', '1101001001'], ['0010000011', '1010011101', '1000110001', '0111101011', '1100001111'], ['0011110011', '0010101101', '0000000100', '1000010010', '1101001000'], ['1110101111', '1011111001', '0101100110', '0100100111', '1010010011'], ['0100010100', '0001110110', '1110111110', '0111110000', '0000001010'], ['1011001011', '0011101111', '1100110011', '1100011001', '1010100011'], ['0110011011', '0001001001', '1111010101', '1110010010', '0100011000'], ['1010011000', '0010111110', '0011101100', '1111011010', '1011101110'], ['1110110011', '1110111100', '0011000101', '1100000000', '0100010001'], ['0100001110', '1011000111', '0101110100', '0011100111', '1110110010']] </code></pre> <p>Is this what you are looking for?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload