Python Web Programming  
 
| Home | Download | Web Links |Zope | Plone |
  >>> ª¹Ô´¢éÍÁÙÅáÅеÑÇá»Ã  
     
  ¢éÍÁÙÅã¹ÀÒÉÒ Python  
 

Number
ÁÕÊͧª¹Ô´¤×Í
1. ¨Ó¹Ç¹àµçÁ (Integer) àªè¹ 40, 122
2. ·È¹ÔÂÁ (floating point) àªè¹ 233.33, 0.75

 
     
  ¡Òäӹdz (Arithmetic)  
 
Python
Operation
Arithmetic
operator
Algebraic
expression
Python
expression
ºÇ¡
+
a+4
a+4
ź
-
a-b
a-b
¤Ù³
*
ab
a*b
¡¡ÓÅѧ
**
ab
a ** b
ËÒÃ
/
// (new in python 2.2)

a/b

a/b
ËÒÃàÍÒàÈÉ
%
a Mod b
a % b
 
     
  µÑÇÍÂèÒ§  
  #!C:\python32\python
# number1.py
# ¡ÒÃÃѺ¢éÍÁÙŨҡ¼Ùéãªé
a = 20
b = 30
c = a + b
print "a + b = ", c
 
  ¼ÅÅѾ¸ì
a + b = 50
 
     
  µÑÇÍÂèÒ§¡ÒÃãªéÊٵäӹdz

Algebra : m =
a+b+c+d+e
-------------------
       5
Python : m = (a+b+c+d+e) / 5
 
     
 
Algebra : m = pr % q + w/x -y
Python : m = p    *    r     %    q    +    w     /     x    -   y
ÅӴѺ     1            2           4           3          5
 
     
  ÅӴѺ¡Òäӹdz
operators
( )
1
**
2
* / // %
3
+-
4
 
     
  µÑÇÍÂèÒ§-Integer  
  #!C:\python32\python
# number2.py
# ¡ÒÃÃѺ¢éÍÁÙŨҡ¼Ùéãªé
n1 = raw_input( "Enter first integer :\n" ) # read a string
n1 = int( n1 ) # convert the string to an integer

n2 = raw_input( "Enter second integer:\n" ) # read a string
n2 = int( n2 ) # convert the string to an integer

sum = n1 + n2 # assignment of sum

print "Sum is", sum # print sum

 
  ¼ÅÅѾ¸ì
Enter first integer : 20
Enter second integer: 30
Sum is 50