close

● Numeric Types

  Integers:Numbers without decimal point

   34653456 or -4586u39

  Floats:Numbers with decimal point

   1111.00134 or -2342.0

● Mathematical Operators

  Integers:
    9 + 5 = 14
    9 - 5 = 4
    9 * 5 = 45
    9 / 5 = 1
    9 % 5 = 4

  Floating-Point Numbers:
    7.0 + 3.0 = 10.0   
    7.0 - 3.0 = 4.0
    7.0 * 3.0 = 21.0
    7.0 / 3.0 = 2.3333
    7.0 % 3.0 = 1.0

  Note:
  as long as there's a floating-point number involved,
  it's considered as a floating-point number calculation.

  ie. 4 + 3.000 = 7.000

● Assignment with operators

   x *= 5 -> x = x * 5
   x /= 5 -> x = x / 5
   x %= 5 -> x = x % 5
   x += 5 -> x = x + 5
   x -= 5 -> x = x - 5

● range()

  ◎ range(x):
     returns a list with values from 0 to x-1

    Input:
     for i in range(10):
      print i,

    Output:
     0 1 2 3 4 5 6 7 8 9

    Note:
     If we take away the comma ( , ) after the i,
     then the output would be

     0
     1
     2
     3
     4
     5
     6
     7
     8
     9

  ◎ range(start, end, g)
    returns a list with value from start to end-1 with gap of g

    Input:
     for i in range(10, 40, 5):
      print i,
     print "\n"
     for j in range(10, 0, -1):
      print j,

    Output:
     10 15 20 25 30 35

     10, 9, 8, 7, 6, 5, 4, 3, 2, 1


arrow
arrow
    全站熱搜

    cosette119 發表在 痞客邦 留言(0) 人氣()