Python
  Home arrow Python arrow Page 9 - Python 101 (part 2): If Wishes Were Pythons
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? 
Google.com  
PYTHON

Python 101 (part 2): If Wishes Were Pythons
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2001-05-31


    Table of Contents:
  • Python 101 (part 2): If Wishes Were Pythons
  • Tax Evasion
  • Q
  • Sliced And Diced
  • Comparing Apples And Oranges
  • If Only...
  • Tying Up The Loose Ends
  • Cookie-Cutter Code
  • Time For Lunch

  • 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 2): If Wishes Were Pythons - Time For Lunch
    ( Page 9 of 9 )

    Python also allows you to combine multiple conditional tests with the "and", "or" and "not" logical operators. If you consider the following code snippet,
    if weekday == "Thursday":
            if time == "12":
                    if place == "Italy":
                            lunch = "pasta"
    
    you'll agree that is both complex and frightening. And so, in addition to the comparison operators we've used so liberally thus far, Python also provides the "and", "or" and "not" logical operators which allow you to group conditional expressions together. The following table should make this clearer.
    
    Assume delta = 12, gamma = 12 and omega = 9
    
    delta == gamma and delta > omega
    True
    
    delta == gamma and delta < omega
    False
    
    delta == gamma or delta < omega
    True
    
    delta > gamma or delta < omega
    False
    
    not delta
    False
    
    Given this knowledge, it's a simple matter to rewrite the example above in terms of logical operators:
    if weekday == "Thursday" and time == "12" and place == "Italy":
            lunch = "pasta"
    
    Simple and elegant, wot?

    And that's about it for the moment. You've learned a lot today - you now know how to manipulate strings and numbers, obtain user input from the command line, and use the "if" family of conditional statements to control the flow of your program.

    In the next article, I'll be discussing some of Python's loops, together with a close look at another very useful and interesting Python data structure - the list. You make sure that you come on back for that one!

     
     
    >>> 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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek