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

python全栈开发—Week1

时间:2017-08-10 01:14:18      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:内存   var   中文   input   字节   开发   and   选择   think   

      第一周主要介绍了python的发展史,以及当前的一些应用情况。

变量

  python的编写过程中会用到许多数据,那为了方便操作,需要把这些数据分别用一个简单的名字代表,方便在接下来的程序中引用,变量就是代表某个数据(值)的名称。     

       1、变量名可以包括字母、数字、下划线,但是数字不能做为开头

  2、系统关键字不能做变量名使用

  

  var = hello world!
  print(var)

 

  执行后

  hello world!

 

字符编码

  字符编码从ASCII,到GB2312、GBK、GBK18030,到现在的万国码Unicode,因为Unicode的英文占用内存太大,所以其中的UTF-8优化后,一个中文字符占3个字节,一个英文字符占1个字节。

 

if else

  

 1 _username = doulen
 2 _password = home1234‘    #声明用户名和密码的变量
 3 
 4 username = input(username:)
 5 password = input(password:)    
 6 
 7 if username == _username and password == _password:
 8     print(welcome {name}, login... .format(name=username))     #只要输入的用户名密码和预先存的一致 那就输出这段话
 9 else:
10     print(username or password is wrong)       #否则 输出这段话

 

 

while循环

 1 true_age = 24
 2 count = 0
 3 while count < 3:
 4     g_age = int(input(age:))
 5     chances = 2-count
 6 
 7     if g_age == true_age:
 8         print(you got it!)
 9         break
10     elif g_age > true_age:
11         print(oops! think smaller, you have %s chances left %(chances))
12     else:
13         print(oops! think bigger, you have %s chances left %(chances))
14     count +=1
15 else:
16     print(you have guessed too many times)

  让用户自行选择继续还是终止

 1 true_age = 24
 2 count = 0
 3 while count < 3:
 4     g_age = int(input(age:))
 5     chances = 2-count
 6 
 7     if g_age == true_age:
 8         print(you got it!)
 9         break
10     elif g_age > true_age:
11         print(oops! think smaller, you have %s chances left %(chances))
12     else:
13         print(oops! think bigger, you have %s chances left %(chances))
14     count +=1
15     if count == 3:
16         countine_comfirm = input(do you want countine?y/n:)
17         if countine_comfirm != n:
18             count = 0

 

python全栈开发—Week1

标签:内存   var   中文   input   字节   开发   and   选择   think   

原文地址:http://www.cnblogs.com/anxyd/p/7336565.html

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