Python
  Home arrow Python arrow Python: More Fun with Strings
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 
IBM Rational Software Development Conference
 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: More Fun with Strings
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-04

    Table of Contents:
  • Python: More Fun with Strings
  • Working with String Methods
  • Capital Idea(s)
  • Putting Our Strings to the Test
  • Converting Data and Sorting

  • 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
     
     
    Web Buyers Guide
     
    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: More Fun with Strings
    (Page 1 of 5 )

    In our last article we left off discussing ways to manipulate strings in Python, like concatenating, repeating, escape characters, and so forth. In this episode we will pick up where we left off and learn some more ways to work with strings, starting with the comparison method.

    Python Tells it Straight: Size Matters

    It's true; Python is a size queen. It's obsessed with comparing strings, numbers, you name it. It may not make a lot of sense, though, as to how Python sees the value of different strings (uppercase Z is less than lowercase A).

    To compare the size of strings, we use the < and > comparison operators, like so:

    (type each of these lines at the command prompt)


    'A' < 'x'

    'X' > 'x'

    '1' > 'z'

    '$' > 'b'

    '$' < '#'

    It should return a True or False, depending upon whether or not the comparison is...well, true or false.

    You can also try these...


    'apples' > 'Apples'

    'Fred' > 'fReD'

    '11111' > '22222'

    And of course you can use Python to compare movies as well:


    'Star Trek' > 'Star Wars'

    'The Matrix' > 'Star Wars'

    'The Matrix' > 'Any Movie'

    See? Python sure does know its movies...

    The rules for which strings are bigger is like so:

    • Letters at the start of the alphabet are smaller than those at the end

    • Capital letters are smaller than lowercase letters

    • Numbers are smaller than letters

    • Punctuation marks (aside from curly braces, pipe characters, and the tilde) are smaller than numbers and letters.

    More Python Articles
    More By James Payne


       · Hey thanks for stopping by for our continued discussion on String manipulation in...
     

       

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




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