Python
  Home arrow Python arrow Python: Stringing You Along
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PYTHON

Python: Stringing You Along
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PYTHON ARTICLES

    - 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
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek