变量处理
guess = 0
teacher = “My tea” 与c++中字符串有相同的处理规则
列表
cher = [1, 2, 3, “hi”, teacher]
功能:
增加元素:
cher.append(4)
cher.extend([10, 20])
cher.insert(2, “world”)
删除元素:
cher.remove(4)
del cher[3]
cher.pop(1)
搜索列表:
if ‘w’ in cher
print(cher[0])
cher[1:2] cher[:2] cher[1:] cher[:] 数组分割
输入输出
print “hello python”
guess = input(“input smth.”)
guess = raw_input()
循环控制
while guess != 0 and tries < 6:
if guess < secret:
print “hello”
for looper in [1, 2, 3]:
for looper in range(1, 5)
for looper in range(5)
for looper in range(5, 1, -1)
for looper in range(1, 5, 2)
continue, break
if a > 0:
print “hi”
elif a == 0:
print “hello”
表达式
5 ** 5
类型
c = 38.0
d = int©
函数
type(x)
def func(para1, para2):
return para1 + para2
类和对象
class Gun:
def init(self):
print(“Gun Init”)
def shoot(self):
print(“Gun Shoot”)
注释
#符号
“”“三引号
注释”""