Python基础(简明Python教程)
基本概念
- 注释符 #
基本数据类型
整数、长整数、浮点数(52.3E-4)、复数(-5+4j)
字符串- 对象
运算符
控制流
- if语句
number = 20
guess = int(raw_input('Enter an integer:'))
if guess == number
print 'true'
elif guess < number
print 'higher'
else:
print 'lower'
- while语句
number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
running = False # this causes the while loop to stop
elif guess < number:
print 'No, it is a little higher than that'
else:
print 'No, it is a little lower than that'
else:
print 'The while loop is over.'
# Do anything else you want to do here
print 'Done'
for语句
取值为[1,2,3,4]
步长默认为1,与foreach相似
fo