1.) python是一种解释语言。python源文件是以py为后缀。
2.) 跟shell 脚本类似
python的源文件头要加入#!usr/bin/python ,
3.) 然后进入源文件目录 chmod a x ,执行跟shell脚本一样./name.py
4.)python 对于空格的要求非常严格。不能跟类C语言一样随意添加空格,末尾没有;分割
python依靠缩写区分代码块。
5)没有switch语句,多重选择使用if ...elif... else...
if guess == number:
print 'Congratulations, you guessed it.' # New block starts here
print "(but you do not win any prizes!)" # New block ends here
elif guess < number:
print 'No, it is a little higher than that' # Another block
# You can do whatever you want in a block ...
else:
print 'No, it is a little lower than that'
# you must have guess > number to reach here
一般需要更多的时候利用字典来解决
阅读(795) | 评论(0) | 转发(0) |