Python
  Home arrow Python arrow Page 3 - Python 101 (part 3): A Twist In The Tail
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 101 (part 3): A Twist In The Tail
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2001-06-13


    Table of Contents:
  • Python 101 (part 3): A Twist In The Tail
  • Here Comes A Hero
  • Making Friends And Influencing People
  • We Don't Need Another Hero
  • Looping The Loop
  • Twist And Turn
  • Within Range()
  • Just Passin' Through

  • 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 101 (part 3): A Twist In The Tail - Making Friends And Influencing People
    ( Page 3 of 8 )

    Lists can be concatenated with the + operator,

    >>> oldFlames = ["Jennifer", "Susan", "Tina", "Bozo The Clown"] >>> superheroes = ["Spiderman", "Superman", "Human Torch", "Batman"] >>> strangeFriends = oldFlames + superheroes >>> strangeFriends ['Jennifer', 'Susan', 'Tina', 'Bozo The Clown', 'Spiderman', 'Superman', 'Human Torch', 'Batman'] >>>
    and repeated with the * operator, in much the same manner as strings and numbers.

    >>> oldFlames * 3 ['Jennifer', 'Susan', 'Tina', 'Bozo The Clown', 'Jennifer', 'Susan', 'Tina', 'Bozo The Clown', 'Jennifer', 'Susan', 'Tina', 'Bozo The Clown'] >>>
    "Slices" of a list can be extracted using notation similar to that used for extracting substrings - take a look:

    >>> oldFlames ['Jennifer', 'Susan', 'Tina', 'Bozo The Clown'] >>> oldFlames[0] 'Jennifer' >>> oldFlames[0:2] ['Jennifer', 'Susan'] >>> oldFlames[0:5] ['Jennifer', 'Susan', 'Tina', 'Bozo The Clown'] >>> oldFlames[0:] ['Jennifer', 'Susan', 'Tina', 'Bozo The Clown'] >>> oldFlames[:3] ['Jennifer', 'Susan', 'Tina'] >>> oldFlames[-4] 'Jennifer' >>> oldFlames[-1] 'Bozo The Clown' >>>
    The built-in len() function can be used to calculate the number of elements in a list,

    >>> superheroes ['Spiderman', 'Superman', 'Human Torch', 'Batman'] >>> len(superheroes) 4 >>>
    while the "in" and "not in" operators can be used to test for the presence of a particular element in a list. A match returns 1 (true), while a failure returns 0 (false).

    >>> superheroes ['Spiderman', 'Superman', 'Human Torch', 'Batman'] >>> "batman" in superheroes 0 >>> "Batman" in superheroes 1 >>> "Batma" in superheroes 0 >>> "Incredible Hulk" in superheroes 0 >>> "Incredible Hulk" not in superheroes 1 >>>


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

       

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