Python
  Home arrow Python arrow Python: Stringing You Along
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Python: Stringing You Along
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-01-28

    Table of Contents:
  • Python: Stringing You Along
  • Making Text Appear Exactly As You Typed It
  • Other Ways to Span Text
  • String Operators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Python: Stringing You Along
    (Page 1 of 4 )

    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!

    In this epic article we will cover the various ways to manipulate string objects in Python. These range from sorting and indexing to some of the built-in string methods. So put down those knitting tools, kick that cat across the room like a football, and let's be like Olivia Newton-John (i.e., let's get physical).

    The Basics

    Here we are going to cover some of the basics of strings. If you need a refresher on them, you can read along. Or, if you are a string writing pro, feel free to skip over this section, or read it and get real bored and send me hate mail. Whichever you choose is fine.

    Printing a string


    #!/usr/local/bin/python

    print "Here are some samples of basic strings:"

    print " "

    print "Now you know and knowing is half the battle"

    print "A"

    print "9"

    print "%#$@!"

    print "It was the best of times, it was the worst of times,"

    print "It was the age of wisdom, it was the age of foolishness"

    print "It was the epoch of belief, it was the epoch of incredulity"

    print "It was the season of Light, it was the season of Darkness"

    print "This quote goes on forever..."

    Storing Strings in Variables and Printing Them


    #!/usr/local/bin/python

    apple = "Fudgebuckets"

    sentence="Look at this! It's a sentence! No wait...it's two sentences!"

    print apple

    print sentence

    Printing Quoted Text


    #!/usr/local/bin/python

    print "And he said to me, 'I pity the fool!' "

    print 'And I quote: "Quit yo jibba-jabba!"'

    print " "

    print "Notice that it is best to use single quotes when you want to do double quotes"

    print "And double quotes when you want to do single quotes"

    More Python Articles
    More By James Payne


       · Thanks for dropping by to read my article on Python strings. In this episode we...
       · Thanks for the article, but the text spanning examples are broken. The backslashes...
       · Hey, thanks for catching that; our content system sometimes gobbles up our...
       · I fixed the article as well. Thanks.-James Payne
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway