Python
  Home arrow Python arrow Page 3 - Python 101 (part 3): A Twist In The Ta...
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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: 5 stars5 stars5 stars5 stars5 stars / 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:
      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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

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

    >>> 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 forextracting 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 elementsin 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 presenceof a particular element in a list. A match returns 1 (true), while afailure 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

    - 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 4 hosted by Hostway