Python
  Home arrow Python arrow Page 5 - Python 101 (part 2): If Wishes Were Py...
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 2): If Wishes Were Pythons
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 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:
      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 2): If Wishes Were Pythons - Comparing Apples And Oranges


    (Page 5 of 9 )

    The examples you've just seen are very rudimentary. To really add some punch, you need to know how to construct what the geeks call a conditional statement. And the very basis of a conditional statement is comparison - for example, "if this is equal to that, do thus and such".

    Python comes with a bunch of useful operators designed specifically for use in conditional statements. Here's a list:

    
    Assume delta = 12 and omega = 9
    Operator What It Means           Expression Evaluates To
    ------------------------------------------------------------------------------
    ==      is equal to                   delta == omega          False
    !=      is not equal to               delta != omega          True
    >       is greater than               delta > omega            True
    <       is less than                  delta < omega            False
    >=      is greater than or equal to   delta >= omega           True
    <=      is less than or equal to      delta <= omega           False
    
    These comparison operators can be used for both strings and numbers. A positive result returns true (1), while a negative result returns false (0).

    An important point to note - and one which many novice programmers fall foul of - is the difference between the assignment operator (=) and the equality operator (==). The former is used to assign a value to a variable, while the latter is used to test for equality in a conditional expression. So

    a = 47;
    assigns the value 47 to the variable a, while

    a == 47
    tests whether the value of a is equal to 47.

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