Hi all the wonderful people out there. I am new to python programming and still struggling to learn it.
I wanted to print a string 10 times with a single line of code. I did the following:
var1="Hello World " - Hello World is defined as var1
print(10*‘Hello World’) - Text Hello World is printed 10 times in a straight line
print(10*‘Hello World\n’) - Text Hello World is printed 10 times vertically on separate lines
print(10*var1) - Text Hello World is printed 10 times in a straight line
print(10* ‘var1\n’) - word var1 is printed 10 times vertically not Hello World while var1 refers to the variable Hello World
I wanted to print the string value stored in var1 a total of 10 times vertically using the \n command. However I am getting he text var1 rather than the value of var1.
This almost does what you want. It is missing the “\n” at the end of the content of var1. Lets add it:
>>> var1 = "Hello world"
>>> print(10*(var1 + "\n"))
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
>>>