Python, multiple printing,

How can I repeat a line several times, several times? I know that I can use a for loop, but I would like to repeat the line xtimes per row, over nrows.

For example, if the user enters 2, the output will be:

@@
@@
@@
@@

Where xequal to 2, and nequal to 4.

+6
source share
9 answers
for i in range(3):
    print "Your text here"

or

for i in range(3):
    print("Your text here")
+8
source

If you want to print something = '@'2 times per line, you can write this:

print(something * 2)

If you want to print 4 lines of something, you can use a for loop:

for i in range(4):
     print(something)
+28
source

, , 2, , :

!!
!!
!!
!!

?

, - :

rows = 4
times_to_repeat = int(raw_input("How many times to repeat per row? ")

for i in range(rows):
    print "!" * times_to_repeat

:

How many times to repeat per row?
>> 4
!!!!
!!!!
!!!!
!!!!

, .

+2

EDIT: .

:

separator = "!" * int(raw_input("Enter number: "))
print separator
do_stuff()
print separator
other_stuff()
print separator
+1
rows = int(input('How many stars in each row do you want?'))
columns = int(input('How many columns do you want?'))
i = 0

for i in range(columns): 
    print ("*" * rows)

i = i + 1
+1

, for?

a=[1,2,3]

for i in a:
    print i
1
2
3


for i in a:
    print i
1
2
3
0
def repeat_char_rows_cols(char, rows, cols):
    return (char*cols + '\n')*rows

>>> print(repeat_char_rows_cols('@', 4, 2))
@@
@@
@@
@@
0

, "" 1000 , .

word = ['HELP']
repeat = 1000 * word

1000 , ,

word_data =pd.DataFrame(repeat)
word_data.columns = ['list_of_words'] #To change the column name 
0

, .

, :

print("Random String \n" * 100), 100 .

0

All Articles