Python: Stringing You Along - String Operators (Page 4 of 4 )
There are several operators you can use on strings. Here is how some of them work:
#!/usr/local/bin/python
first ="James "
last ="Payne "
truth ="Is a bad mamma jamma"
print "Here is an example of concatenating string variables:"
print first+last+truth
print "n"
print "Here is another example of concatenating strings:"
print "I like it " + "When you call me " + "Big Poppan "
print "And here is an example of how to repeat text with variables:"
print first *3
print "You can also print it on three separate lines:"
print (first + "n") * 3
print "You can also concatenate and repeat (as we did above):"
print (first+last+truth+ "n") * 4
Note that I put a space in my strings. If I had not, the words would be bunched together. Here is the result:
Here is an example of concatenating string variables:
James Payne Is a bad mamma jamma
Here is another example of concatenating strings:
I like it When you call me Big Poppa
And here is an example of how to repeat text with variables:
James James James
You can also print it on three separate lines:
James
James
James
You can also concatenate and repeat (as we did above):
James Payne Is a bad mamma jamma
James Payne Is a bad mamma jamma
James Payne Is a bad mamma jamma
James Payne Is a bad mamma jamma
Well that's it for this tutorial. We still have more string-a-ma-things to cover, and we will do so in the next article. So come back often and get dat learn on son.
Till then...
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |