Python
  Home arrow Python arrow Python: More Fun with Strings
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? 
PYTHON

Python: More Fun with Strings
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    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:
      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: 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
     

       

    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 6 Hosted by Hostway
    Stay green...Green IT