第一个Python程序(Day3)

一    Python 解释器执行Python程序的过程    

        eg:python3 C:\ test.py

  1.启动python解释器 (内存中)

  2.将C:\ test.py中的内容从硬盘读入内存

  3.执行读入内存的代码

  

如果想要永久保存代码,就要用文件的方式

如果想要直观的调试代码,就用交互式的方式

(一)变量

  一个是变:  核心在于变化

  一个是量:  衡量,计量,表达的一种状态

变量的定义

 

声明一个变量

eg:name = “Mr shao”

变量的定义规则

  变量名只能是 字母、数字或下划线的任意组合

  变量名的第一个字符不能是数字

  以下关键字不能声明为变量名['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

  定义方式

驼峰体

AgeOfOldboy = 56 
NumberOfStudents = 80

下划线
age_of_oldboy = 56
number_of_students = 80


定义变量不好的方式举例

  变量名为中文、拼音

  变量名过长

  变量名词不达意

(二)常量

常量即指不变的量,如pai 3.141592653..., 或在程序运行过程中不会改变的量

二    程序交互

        ————读取用户输入

 

name = input("what is your name?")
print("Hello"+name)

执行脚本就会发现,程序会等待你输入姓名后再往下继续走。

可以让用户输入多个信息,如下

name = input("what is you name?")
age = input("How old are you?")
hometown = input("Where are you from?")
print("Hello",name,"you are"age,"yours old ,you came from",hometown)


执行输出


What is your name?Mr shao
How old are you?22
Where is your hometown?ShanDong
Hello  Mr shao your are  22 years old, you came from ShanDong


注释
代码注释分单行和多行注释, 单行注释用#,多行注释可以用三对双引号""" """









 
posted @ 2017-07-14 15:30  NeitherCandidate  阅读(169)  评论(0编辑  收藏  举报