Printing same strIng many times


 
Thread Tools Search this Thread
Top Forums Programming Printing same strIng many times
# 1  
Old 03-21-2012
Printing same strIng many times

In python how we need to print a same string many times without using loop.
I cane across something like * operator for this .
How we Can use this in a print statement ?
I am using python 3.x
Please help me
# 2  
Old 03-21-2012
In python
Code:
print "ABCD" * 4

---------- Post updated at 03:01 PM ---------- Previous update was at 02:59 PM ----------

Code:
 
$ python -c "print \"ABCD\" * 4"
ABCDABCDABCDABCD

---------- Post updated at 03:04 PM ---------- Previous update was at 03:01 PM ----------

In Perl

Code:
 
$ perl -e 'print "ABCD" x 4'
ABCDABCDABCDABCD

# 3  
Old 03-21-2012
Will that work in python 3.x?
I ll chk and let you know
# 4  
Old 03-21-2012
i am using 2.6.4

so it will work in 3.x
# 5  
Old 03-21-2012
Please find the result:
Code:
>>> print "ABCD" * 4
SyntaxError: invalid syntax
>>> print ("ABCD" * 4)
ABCDABCDABCDABCD

My version is :
Code:
>>> import sys
>>> sys.version
'3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]'

# 6  
Old 03-21-2012
if you are inside the python console, they try the below

Code:
 
>>> 'abc' * 4 
'abcabcabcabc'

# 7  
Old 03-21-2012
Yes. its working.
Code:
>>> 'abc' * 4
'abcabcabcabc'

May i know is it possible to customize the ">>>" to "|||" in python console?
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace string and create new file multiple times

First of all, apologies if this has already been answered elsewhere. I haven't quite been able to find what I'm looking for yet, so hopefully this won't come across as repetition. I have a file consisting of ~100 nearly identical lines, each of which contains multiple instances of the string I... (11 Replies)
Discussion started by: pseudo.seppuku
11 Replies

2. Shell Programming and Scripting

Print String N times the number before it

Hey All, I want want to print a string N times the number N before it. Like i have "20 hello". so i want to print hello hello hello . . . . . 20 times.. Please help me.. I am not able o figure out.. how to do the same? (8 Replies)
Discussion started by: jaituteja
8 Replies

3. Shell Programming and Scripting

Help printing string

Hi, I have a file containing many times the word "IPaddress". and i need a command that finds that string or word and print it only once. I've tried the following but they print a line for each match: grep "IPaddress" /directory/file.xml find . | xargs grep 'IPaddress' -sl i have many... (2 Replies)
Discussion started by: blacksteel1988
2 Replies

4. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

5. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

6. UNIX for Dummies Questions & Answers

Find string multiple times, same line

Hi everybody, Fairly simple question here: I need an awk, sed, or grep command that will find the same string multiple times on one line needs to return all lines which contain .02 twice. I do know the exact number of characters in between the two occurrences of .02 if that helps, all... (7 Replies)
Discussion started by: jgrosecl
7 Replies

7. Shell Programming and Scripting

printing each line in a file X times

This is probably simple but I would like to print every line in a file 5 times like this: awk 'NR' mens_csv.tab Dub Tank 53%Hemp/42%Cotton/5%Lycra Jersey Dark Green 0 $22.50 Dub Tank 53%Hemp/42%Cotton/5%Lycra Jersey Indigo Blue 0 $22.50 --------------- Dub... (4 Replies)
Discussion started by: Autumn Tree
4 Replies

8. UNIX for Dummies Questions & Answers

Printing a part of a string

hi I have the input as follows ABC =893 JKL = "jee" alias PQR = 9833 alias STUVE = "kuiue" I should be able to print as follows ABC JKL alias PQR alias STUVE Thanks Suresh (7 Replies)
Discussion started by: ssuresh1999
7 Replies

9. Shell Programming and Scripting

printing strings in one X number of times from another

I have one file of numbers 4 5 2 ... And another file of strings aaaaa bbbbb ccccc ddddd eeeee ffffff ... I'd like to print the stings from each line in reverse order with some decoration the number of times listed in the first file such as: Yeah bbbbb aaaaa Yeah bbbbb aaaaa (5 Replies)
Discussion started by: dcfargo
5 Replies

10. Shell Programming and Scripting

count times for one string

I have a file. I want to count the time for one string appears in this file Example: 56 73 34 79 90 56 34 Expected results 2:56 1:73 2:34 (1 Reply)
Discussion started by: anhtt
1 Replies
Login or Register to Ask a Question