python22期第一天(课程总结)

1.Python介绍:

      python是一门高级编程语言,涉及领域比较广泛,社区活跃,由一个核心开发团队在维护,相对其他语言,易于学习,可移植性强,可扩展性强,易于维护,有大量的标准库可供使用。

   

2.Python版本:

      目前比较流行的版本:python2.7,python3

      解释器类型:
         - cpython解释器(*)
         - jpython解释器
         - ironPython解释器
         - rubyPyhton解释器
         .....
         - pypy解释器

 

        

3.语言吧编码格式(任意语言都遵循本编码格式)     

ascii:用1个字节=8位来表示计算机能表达的所有东西。
        2**8 = 256
        00000000 -> A
        00000001 -> B
        00000010 -> C
        00000011
        00000100
unicode: 万国码,用4个字节=32位来做对应关系
        2**32 = 4294967296
        00000000 00000000 00000000 00000000 -> A
        00000000 00000000 00000000 00000001 -> B
        00000000 00000000 00000000 00000010 -> C
        00000000 10000000 00010000 00011010 -> 紫
utf-8: 对万国码进行压缩,至少使用1个字节表示
        00000000
        00000001
        00000010
        10000000 00010000 00011010
PS: 中文3个字节=24位
        gbk:对亚洲国家的文字做的对应关系
        PS: 中文2个字节=16位

 

4.python专门边开发的IDE工具:python

 

5.开始python编程:

     5.1 输出:print("你是风儿我是沙")
     输入:user = input("请输入用户名:")
     密码加密:
     import getpass
     pwd = getpass.getpass("请输入密码:")

 

     5.2 变量:

     格式: 变量名 = 值

   规范:

      a. 数字、字母、下划线

      b. 不能以数字开头

      c. 不能使用Python的关键字

      建议:见名知意; user_pwd = "xxx"

注意:
示例一:
name = 'alex'
user = 'alex'

示例二:
name = 'alex'
user = name

 

5.3 条件语句判断

    格式一:
    if 条件:
      成功之后走这里

    格式二:
    if 条件:
      成功之后走这里
    else:
      失败之后走这里

    格式三:
    if 条件:
      成功之后走这里
    elif 条件:
      成功之后走这里
    elif 条件:
      成功之后走这里
    else:
      上述都失败

 

6. 循环语句:

    while 条件:
      条件成立执行


    while True:
      print('钓鱼要钓刀鱼,刀鱼要到岛上钓')


    while 1==1 and 2==2:
      print('钓鱼要钓刀鱼,刀鱼要到岛上钓')

    timer = 0
    while timer < 3:
      print('钓鱼要钓刀鱼,刀鱼要到岛上钓')
      timer = timer + 1

    print('完成')

 

7.常用的数据类型:

整数:
            age = 18 
        字符串:
            name = "紫薇"
            # 获取紫
            n1 = name[0]
            n2 = name[1]
        列表:
            user_list = ["紫薇","尔康","18","海量","小鸡"]
            n3 = user_list[0]
            n4 = user_list[1] # "尔康"
            
            user_list = ["紫薇","尔康","18","海量","小鸡"]

            for xxx in  user_list:
                print(xxx)
                if xxx == '18':
                    break
        字典:
            user_info = {"name":"紫薇","age":18}
            
            
            n5 = user_info["name"]
            n6 = user_info["age"]
            
            user_info['count'] = 666
            # {"name":"紫薇","age":18,"count":666}
        
        数据类型嵌套:
        
            n7 = ["alex","eric",[11,22,33]]
            
            n7[1]
            n7[2][1]
            
            n8 = [
                "alex",
                {'name':'日天','age':18},
                [11,22,33]
            ]
            n8[1]["age"] = 19 

 

 小小练习题:

问题: 循环用户列表,打印用户姓名和密码
                user_list = [
                    {'username':'alex', 'password':'123', 'count':0 },
                    {'username':'eric', 'password':'123', 'count':0 },
                    {'username':'tony', 'password':'123', 'count':0 },
                    {'username':'oldboy', 'password':'123', 'count':0 },
                ]
                
                for item in user_list:
                    print(item['username'],item['password'],item['count'])
                    
            问题: 将每个用户的count改成1
                user_list = [
                    {'username':'alex', 'password':'123', 'count':0 },
                    {'username':'eric', 'password':'123', 'count':0 },
                    {'username':'tony', 'password':'123', 'count':0 },
                    {'username':'oldboy', 'password':'123', 'count':0 },
                ]
                for item in user_list:
                    if item['username'] == 'alex' and item['password'] == '123':
                        item['count'] = 1
                    print(item)
                                    
            问题: 用户输入用户名和密码,在user_list中进行校验
                user_list = [
                    {'username':'alex', 'password':'123' },
                    {'username':'eric', 'password':'123'},
                    {'username':'tony', 'password':'123'},
                    {'username':'oldboy', 'password':'123'},
                ]
                
                
                user = input("请输入用户名:")
                pwd = input("请输入密码:")
                
                
                flag = False 
                
                for item in user_list:
                    if item['username'] == user and item['password'] == pwd:
                        flag = True 
                        break
                    else:
                        pass
        
                if flag:
                    print("登录成功")
                else:
                    print("登录失败")

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2018-05-07 16:05  MR_dy  阅读(312)  评论(0)    收藏  举报