How to print a string multiple times?
for i in range(3):
print "Your text here"
Or
for i in range(3):
print("Your text here")
How to print a character or string in multiple times in c++
To do what you want you can do this:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x;
char chars = '*';
cin >> x;
for (int i=1; i<=x; i++){
cout << chars;
}
cout << "\n\n";
system("pause");
return 0;
}
Display string multiple times
Python 2.x:
print '-' * 3
Python 3.x:
print('-' * 3)
What is a pythonic way to print a string multiple times on one line, separated by spaces?
Put the string in a list
print(' '.join(['hello']*3))
'hello hello hello'
Print elements of string multiple times based on position
You can enumerate iterables (lists, strings, ranges, dictkeys, ...) - it provides the index and a value:
text = "abcdef"
for idx,c in enumerate(text):
print(idx,c)
Output:
(0, 'a')
(1, 'b')
(2, 'c')
(3, 'd')
(4, 'e')
(5, 'f')
You can use that to print something multiple times. The print command takes 2 optional parameters :
print("Bla","blubb", sep=" --->", end=" Kawumm\n")
Output:
Bla --->blubb Kawumm
that specify what is printed between outputs and on the end of output - you can specify an end=""
- so you can continue printing on the same line.
Doku:
- Enumerate
Edit:
user_string = input()
def accum(s):
t = [] # list to store stuff into
for count, letter in enumerate(s):
total = letter.upper() + letter * (count) # 1st as Upper, rest as is
t.append(total) # add to list
print(*t, sep="-") # the * "unpacks" the list into its parts
accum(user_string)
Unpacking:
print( [1,2,3,4,5], sep=" +++ ") # its just 1 value to print, no sep needed
print(*[1,2,3,4,5], sep=" +++ ") # 5 values to print, sep needed
Output:
[1, 2, 3, 4, 5]
1 +++ 2 +++ 3 +++ 4 +++ 5
Print character multiple times
You can print in the same line with System.out.print(" _");
so you can use a loop. print
instead of println
does not append a new line character.
for (int i=0; i<5; i++){
System.out.print(" _");
}
Will print: _ _ _ _ _
.
Related Topics
How to Locate the Index With in a Nested List Python
Python Executable Not Finding Libpython Shared Library
Python - Outputting Variables to Txt File
Pandas - Drop Last Column of Dataframe
Pyodbc Error Data Source Name Not Found and No Default Driver Specified Paradox
How to Delete Lines from CSV File Using Python
Json Valueerror: Expecting Property Name: Line 1 Column 2 (Char 1)
How to Get Value from Json List Within Robot Framework
Convert SQL Result to List Python
Remove Last Few Characters in Pyspark Dataframe Column
Python: Element Is Not Attached to the Page Document
Replace Empty Strings With None/Null Values in Dataframe
Python - How to Separate Paragraphs from Text
Conditional Row Read of CSV in Pandas
Python: Import Cx_Oracle Importerror: No Module Named Cx_Oracle Error Is Thown