Python-入门第三篇

行和缩进

学习Python与其他语言最大的区别就是,Python的代码块不使用大括号({})来控制类,函数以及其他逻辑判断。python最具特色的就是用缩进来写模块。

缩进的空白数量是可变的,但是所有代码块语句必须包含相同的缩进空白数量,这个必须严格执行。

在Python的代码块中必须使用相同数目的行首缩进空格数。

等待用户输入

#!/usr/bin/python

raw_input("\n\nPress the enter key to exit.")

注:Python中注释使用‘#’

#!/usr/bin/python

#This is input……
raw_input("\n\nPress the enter key to exit.")

命令行参数

很多程序可以执行一些操作来查看一些基本信,Python可以使用-h参数查看各参数帮助信息:

$ python -h 
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... 
Options and arguments (and corresponding environment variables): 
-c cmd : program passed in as string (terminates option list) 
-d     : debug output from parser (also PYTHONDEBUG=x) 
-E     : ignore environment variables (such as PYTHONPATH) 
-h     : print this help message and exit 

 

#!/usr/bin/python
#encoding=utf-8
#print(raw_input("请输入一个汉字:"))

#print [i for i in range(5)]
num=[]
for i in range(5):
    num.append(raw_input("请输入一个数:"))

print num
max=0
for i in range(5):
    if (int)(num[i])>(int)(max):
        max=num[i]
        print '=====',max,'====',i

print 'Max=',max

#while True:
#    reply=input('Enter text:')
#    if reply=='stop':break
#    print(reply.upper())

 

posted @ 2014-08-07 08:44  爱在夕阳下  阅读(181)  评论(1编辑  收藏  举报