Python
  Home arrow Python arrow Page 7 - Python 101 (part 5): Snake Oil For The...
Dev Shed Forums 
Administration  
AJAX  
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 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
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 101 (part 5): Snake Oil For The Soul
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2001-07-09

    Table of Contents:
  • Python 101 (part 5): Snake Oil For The Soul
  • Air In A Bottle
  • Treading The Right Path
  • Standing In Line
  • Learning To Write
  • Desperately Seeking Python
  • String Theory
  • Pop() Goes The Weasel

  • 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


    Python 101 (part 5): Snake Oil For The Soul - String Theory


    (Page 7 of 8 )

    Now, in addition to the various methods already explained in this andprevious articles, Python 2.0 comes with a whole bunch of new methods forthe various data types you've studied. Over the next couple of pages, I'dlike to briefly illustrate these with some examples.

    A number of string methods are available to convert and check stringformats - take a look:

    >>> # string methods >>> str = "jackfrost" >>> # check for lowercase >>> str.islower() 1 >>> # check for uppercase >>> str.isupper() 0 >>> # capitalize first character >>> str.capitalize() 'Jackfrost' >>> # convert to uppercase >>> str.upper() 'JACKFROST' >>> # convert to lowercase >>> str.lower() 'jackfrost' >>> # let's try another string >>> str = "Jack Frost" >>> # check if this is a title >>> str.istitle() 1 >>> # split string and return sections as list >>> str.split(" ") ['Jack', 'Frost'] >>> str.swapcase() 'jACK fROST' >>> str = "Mummy" >>> # count number of occurrences within a string >>> str.count("m") 2 >>>
    Incidentally, the count() method also works with lists.

    >>> list = ["red", "green", "blue", "red", "yellow", "blue", "black", "white", "green"] >>> list.count("green") 2 >>>

    More Python Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PYTHON ARTICLES

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





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT