屏幕输出指令 ——print "Welcome to Python!"
定义变量 ——my_bool = 10(自动识别数据类型)
my_float=1.23
结构代码 ——空白,即是缩进来表现结构,而非c的;
注释 ——#后;多行注释用三组引号括起来" " "bla..bla.." " "
计算 ——+ - * /;幂计算2**3(2的三次方);取余%
string ——" "括起来定义,若想在其中加入单引号,在前添加\;c="cats"[0](下标输出制定字符);
len(string)返回string长度;parrot.lower()所有字符小写;parrot.upper()大写;
str(2)将2转换为“2”,即转换为字符串;isalpha()判断是否全为字母;
[1:len(new_word)]分割string
输出 ——print anything;print"Life " + "of " +"Brian";
print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)
name = raw_input("What is your name?")
quest= raw_input("What is your quest?")
color = raw_input("What is your favorite color?")
print "Ah, so your name is %s, your quest is %s, " \
"and your favorite color is %s." % (name, quest, color)
导入库 ——from datetime import datetime
记录当前时间 ——now=datetime.now();now.year;now.month;now.day;now.hour, now.minute, and now.second.
输入 ——answer = raw_input("Type left or right and hit 'Enter'.").lower()
函数定义 ——def square(n):
"""Returns the square of a number."""
squared = n**2
print "%d squared is %d." % (n, squared)
return squared