Home arrow Python arrow Page 7 - Python 101 (part 5): Snake Oil For The Soul

String Theory - Python

Now that you know how to create and use Python's tuples, listsand dictionaries, it's time to get your hands dirty. In this article, findout how to read from, and write to, files on the filesystem with built-inPython methods, and also take a look at some of the new features availablein Python 2.x.

  1. Python 101 (part 5): Snake Oil For The Soul
  2. Air In A Bottle
  3. Treading The Right Path
  4. Standing In Line
  5. Learning To Write
  6. Desperately Seeking Python
  7. String Theory
  8. Pop() Goes The Weasel
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 4
July 09, 2001

print this article


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- 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

Developer Shed Affiliates


Dev Shed Tutorial Topics: