Home arrow Python arrow Page 4 - Python: Stringing You Along

String Operators - Python

If you have ever programmed before, or are a ninety-year-old lady, or a cat, then you know how useful strings are. If you have been reading these articles, you will know that a string is a character, a sentence, a paragraph, a book, etc. If you haven't been reading these articles, then you're missing an important part of your education as a programmer. Don't keep yourself in the dark; start reading!

TABLE OF CONTENTS:
  1. Python: Stringing You Along
  2. Making Text Appear Exactly As You Typed It
  3. Other Ways to Span Text
  4. String Operators
By: James Payne
Rating: starstarstarstarstar / 5
January 28, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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



 
 
>>> More Python Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: