python 学习笔记

  • Python Syntax
    • 函数定义: “def function:”
    • 单行注释(comment):在行首加'#'
    • 多行注释: """text……text"""
    • 乘幂:10 ** 2 (表示10的2次方)
  • Tip Calculator
    • 15 / 100 的结果为0,就是说python中整数默认变量类型还是整数。
  • Strings & Console Output
    • 和c++一样的转义字符:'\''
    • 可以直接把固定字符串当做指针变量用:fifth_letter = "MONTY"[4]
    • 取字符串长度:len("text")
    • 返回所有字符变成小写的字符串:text.lower()
    • 返回所有字符变成大写的字符串:text.upper()
    • 返回转化后的字符串(d可为任意非字符串变量):str(d)
    • print "text" + str(3.14)   (不能直接print "text" + 3.14)
    • print "%s, %s" % (str1, str2)
    • quest = raw_input("What is your quest?")  与c++中 scanf("What is your quest?%s", &quest) 类似
  • Date and Time
    • from datetime import datetime
    • now = datetime.now()
      • now.date()
      • now.year, now.month, now.day (字符串类型)
      • now.hour, now.minute, now.second
  • Conditionals & Control Flow
    • if answer == "left" or answer == "l":
              print "This is the Verbal Abuse Room, you heap of parrot droppings!"
          elif answer == "right" or answer == "r":
              print "Of course this is the Argument Room, I've told you that already!"
          else:
              print "You didn't pick left or right!"
      //if 语句
    • not 即为 ! 

    • not > and > or
posted @ 2014-09-15 12:23  ooyyloo  阅读(108)  评论(0编辑  收藏  举报