Python
  Home arrow Python arrow Page 2 - 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 - Tax Evasion
    (Page 2 of 9 )

    The first - and simplest - object type you're likely to encounter is the number. I've already shown you a few examples of how Python treats numbers last time - but here's a quick refresher anyway:

    Python 1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731 (experimental)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> print 24+1 25 >>> print 12*10 120 >>> print 65/5 13 >>> print 15-9 6 >>>
    There are four basic number types available in Python:

    Integers: These are plain-vanilla numbers like 23, 5748, -947 and 3; they are also the most commonly-used type.

    Floats: These are typically decimal numbers, although Python also allows you to use the scientific notation to represent them - for example, 3.67, 98.573 or 5.347e-17.

    Long integers: These are integer values which are too large to be handled by the regular Integer type - for example, 45734893498L or 53267282982L. Note the uppercase "L" appended to the end of a long integer, which makes this type easier to identify.

    Complex numbers: You may remember these from algebra class (I don't, but that's probably because I slept my way through college) - 2.5+0.3j, 4.1-03.j and so on. These numbers can be broken up into "real" and "imaginary" parts...the "imaginary" part is what you bank, while the "real" part is what the government takes away in taxes.{mospagebreak title=Putting Two And Two Together} Most of the time, you'll be working with integers and floats; the other two types are typically used for specialized applications. And as the example above demonstrates, Python allows you to add, multiply, divide and otherwise mess with these numbers via simple arithmetic operators. Here's an example which demonstrates the important ones:

    >>> alpha = 10 >>> beta = 2 >>> # standard stuff ... sum = alpha+beta >>> sum 12 >>> difference = alpha-beta >>> difference 8 >>> product = alpha*beta >>> product 20 >>> quotient = alpha/beta >>> quotient 5 >>> # non-standard stuff ... remainder = alpha%beta >>> remainder 0 >>> exponent = alpha**beta >>> exponent 100 >>>
    As with all other programming languages, division and multiplication take precedence over addition and subtraction, although parentheses can be used to give a particular operation greater precedence. For example,

    #!/usr/bin/python print(10 + 2 * 4)
    returns 18, while

    #!/usr/bin/python print((10 + 2) * 4)

    returns 48.

    It should be noted at this point that Python does not support the popular auto-increment (++) and auto-decrement (--) operators you may have used in Perl, PHP and JavaScript.

    There are also some built-in functions you can use with Python numbers - the most useful are abs() and pow(), which return the absolute value of a number and raise one number to the power of another. Take a look.

    >>> alpha = -89 >>> abs(alpha) 89 >>> pow(3,2) 9 >>>


     
     
    >>> 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-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek