码迷,mamicode.com
首页 > 编程语言 > 详细

Python_day1

时间:2017-07-14 20:26:40      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:comm   pytho   ring   原则   com   代码注释   好的   shandong   world   

一、HelloWorld

>>>print("Hello World!")

>>>
Hello World!

二、变量

   1、什么是变量 :

           name = "Fugui"

name----变量名
Fugui---变量值

  2、标识符命令规范:
  1. 变量名只能是 字母、数字或下划线的任意组合
  2. 变量名的第一个字符不能是数字
  3. 以下关键字不能声明为变量名
  4. [‘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‘]
 
  3、定义方式:

驼峰体


AgeOfOldboy = 56 
NumberOfStudents = 80

下划线

age_of_oldboy = 56 
number_of_students = 80
 

4、定义变量不好的方式举例:

      • 变量名为中文、拼音
      • 变量名过长
      • 变量名词不达意

 

    5、常量:

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

三、程序交互

1、读取用户输入:

 

name = input("What is your name?")

print("Hello " + name )

 

 

 

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

 

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

 

name = input("What is your name?")
age = input("How old are you?")
hometown = input("Where is your hometown?")

print("Hello ",name , "your are ", age , "years old, you came from",hometown)

 

 

 

执行输出

 

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

           2、注释:

                

代码注释原则:

      1. 不用全部加注释,只需要在自己觉得重要或不好理解的部分加注释即可
      2. 注释可以用中文或英文,但绝对不要拼音噢

Python_day1

标签:comm   pytho   ring   原则   com   代码注释   好的   shandong   world   

原文地址:http://www.cnblogs.com/yifugui/p/7171996.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!