Home > Enterprise >  How can I make a variable n zeros?
How can I make a variable n zeros?

Time:11-02

So I want to create something like

myvariable = n * 0

but I want zeros to repeat N times back to back (not on different lines)

How can I do this?

CodePudding user response:

>>> n = 5
>>> myvariable = n * '0'
>>> print(myvariable)
00000

CodePudding user response:

if you use multiply operator with a string in python, It repeats your string n times.

For example :

N = 3
yourString = "python"

when you use this code:

print(N * yourString)

it will return "python" three times:

Output: pythonpythonpython

  • Related