How to string format in python? [duplicate] - python-2.7

This question already has answers here:
Converting a number to binary with a fixed length
(9 answers)
Closed 6 years ago.
I have a new python learner, I want to ask a question about string format.
a = 3
len = 5
I want to format a as a binary number and the number length is 5. So I want to format it to '00011'.
How can I do in python?

answer = format(a,'b').zfill(len)

Related

How would I add or multiply extremly large numbers e.g. 20 digit number x 5 digit number...? [duplicate]

This question already has answers here:
Big numbers library in c++ [closed]
(4 answers)
Store and work with Big numbers in C
(3 answers)
Closed 2 years ago.
I'm new to c++ so I don't know if there are any specific libraries that could do this. Any help would be appreciated!

List of some number ([1,1,1,1,1,1]) in haskell [duplicate]

This question already has answers here:
'Repeat' in Haskell?
(4 answers)
Closed 2 years ago.
Is it possible in Haskell to create list of some element by provided length?
In Python, I can write:
l = [1] * 10
How can I do it in Haskell?
Thanks to Krzysztof Atłasik
replicate 10 1

Random Number Generator with Range - Swift 3? [duplicate]

This question already has an answer here:
How to generate a random number in a range (10...20) using Swift [duplicate]
(1 answer)
Closed 6 years ago.
Need to set a random number between say 3 and 7. Everything I find is for Swift 2 and no longer works in Swift 3.
Thanks
This should work for my purposes.
var tapsNeeded = arc4random_uniform(4) + 3;

Date regular expression in VB [duplicate]

This question already has answers here:
Regular Expression to match valid dates
(16 answers)
How do I match an entire string with a regex?
(8 answers)
Closed 6 years ago.
I want to validate MM/YYYY in VB6
I used (0[1-9]|1[012])/(19|20)[0-9]{2}
But it is not working as expected. Even it allows 5 digit year.

Regex number match [duplicate]

This question already has answers here:
Regex match entire words only
(7 answers)
Closed 6 years ago.
How can I get a match when numbers are 5 or 7 digits long with these parameters?
If I understand your question correctly, this (visualize here) should do it:
`/\b([5-9]\d{4}(?:\d{2})?)\b/`