close

● raw_input("String")

  Usage:
   String name = raw_input("Hi. What's your name?")
   then the program takes the user input and assign it to name

● Print Statement

  Input:
   print "ABCDEFG",
   print "HIJKLMN"

  Output:
   "ABCDEFG HIJKLMN"

  Note:
   Notice the space between the first and second print statements
   That is created by the comma ( , )

  OR

  Input:
   print >> sys.stdout, "ABCDEFG"

  Output:
   "ABCDEFG"

  Note:
   Notice the 〝sys.stdout〞 after the 〝>>〞,
   if we change the 〝stdout〞 to 〝stderr〞
   then the message will be treat as an error message.

● Breaking up statements

  When you need to break a line into two,
  just use \ at any place where you can place a space

  example:

   print "XXXXXXXXXXXXXXXXXXXXXXXXXX" + "ZZZZZZZZZZZZZZZZZZZZZZZ"

   is equals to

   print "XXXXXXXXXXXXXXXXXXXXXXXXXX" + \
   "ZZZZZZZZZZZZZZZZZZZZZZZ"

● Changing type

   ◎ float(x) Return a floating-point valu by converting x
     float("10") = 10.0

    int(x) Return a integer value by converting x
     int("10") = 10

    str(x) Return a string value by converting x
     str(10) = "10"

● Using inport statement

  If we need to use a module, we use import statement.
  take module 〝random〞 for example:

  import random

  is all we need to type for using module random in our function

● len()

  ◎ String:
    s = "012345678"
    len(s) = 9

  ◎ List:
    s = [0, 1, 2, 3, 4, 5, 6]
    len(s) = 7

  ◎ Map:
    s = {a:A, b:B, c:C, d:D}
    len(s) = 4


arrow
arrow
    全站熱搜

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