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...