python基础

  1. python优点: 简单易学 、免费开源、丰富的库、可扩展性、可移植性、面向对象、规范的代码。

  2. 变量的类型:

    • 数字-int、float
    • 布尔-True、False
    • 字符串 str
    • 列表 list
    • Tuple 元组
    • Dict 字典
  3. 标识符命名规则:三大命名规则:大驼峰、小驼峰、下划线。

  4. 如何在python中查找关键字

    python
    help ('keywords')

  5. 常用的格式符号有哪些(3个即可)

    • %s---字符串
    • %d---十进制的整数(int)
    • %f---浮点
    • %c---字符
  6. 运算符(至少5个)

    + - * / % 
    
  7. python常用的数据类型转换(至少3个)

    • Int(x)
    • float(x)
    • str(x)
    • list(s)
    • tuple(s) s代表的序列
  8. 比较运算符(至少3个)

    >= <= != 
    
  9. 逻辑运算符是哪3个

    and,or,not

  10. 自己写一个if-elif-else条件语句并输出

    a = int(input('请输入分数:'))   
    if a <= 70:                
        print('成绩不及格')         
    elif 70 < a <= 80 :        
        print("成绩良好")          
    else:                      
        print('成绩优秀')          
    
  11. 通过程序写一个等边三角形

    for i in range(1,6):                 
        for j in range(1,6-i):           
            print(" ",end="")            
        print("* "*i)              
    
  12. 通过程序写一个九九乘法表

    i = 1
    while i<= 9:
        j=1
        while j<=i:
            print('%d*%d=%d'%(i,j,i*j), end=' ')
            j+=1
        print('\n')
        i +=1
    
  13. 通过代码针对str="abcdefg" :
    1取出bcd
    2将str倒序
    3取出bdf

    str="abcdefg"            
    a = str[1:4]             
    print(a) 
              
    b = str[::-1]            
    print(b)
                             
    c = str[1::2]            
    print(c)                 
    
    
  14. 通过代码针对mystr = "hello world python and python"进行如下操作
    1.找到右边第一个p的索引
    2.找z结果要求报错
    3.将所有空格替换成逗点
    4.通过逗点生成一个列表
    5.将d全部替换成大写D

    a = mystr.rfind("p")           
    print(a)                       
                             
                             
    b = mystr.find('z')            
    if b == '-1':                  
      print('查无此字')          
                             
    c = mystr.replace(' ',',')     
    print(c)                       
                             
    d = c.split(",")               
    print(d)                       
                             
    e=mystr.replace('d','D')       
    print(e)                       
    
  15. a = [1,2,3,4,5,6],在a中元素5前添加一个5.5元素
    在a中元素6后面添加"我心态炸了"
    删除a中的元素1

    a = [1,2,3,4,5,6]     
    a.insert(4,5.5)       
    print(a)              
                    
    a.append('我心态炸了')     
    print(a)              
                    
    a.remove(1)           
    print(a)                    
    
  16. b = ["a","b","c","b","a"] 查找索引区间在2-4的“b”的索引,查找索引区间在3-4的“a”的索引。

    b = ["a","b","c","b","a"]   
    a=b.index('b',2,5)          
    print(a)                    
    c=b.index('a',3)            
    print(c)                    
                              
    
  17. 试着修改一个自己创建的元组,达到报错的目的,提醒自己元组不可修改

    try:                    
        a = (0,1,2,3,4)     
        print(a.append(1))  
    except Exception as e:  
        print(e)            
    
  18. 自己写一个字典,计算自己写的字典中存在键值对的个数,找出字典中所有的key,找出字典中所有的value,试着遍历字典中的item,最后删除字典中的第一个键所对应的数据

    item={'name':'lsc','age':3,'school':'jy','class':1907}         
    for i in item.keys():                                          
        print(i)                                                   
    for i in item.values():                                        
        print(i)                                                   
    for i in item:                                                 
        print(i)                                                   
    del item['name']                                               
    print(item)                                                    
    
  19. 集合中的discard的概念

    discard() 方法从集合中删除指定项目。

  20. 试着自己写两个集合,分别进行 & 和 | 的操作

    item1={'name','lsc','age',3}                
    item2={'school','lsc','class',1907}         
                                          
    item = item1 | item2                        
    print(item)                                 
                                          
    item = item1 & item2                        
    print(item)                                 
    
  21. 如果以上觉得没挑战,思维扩展:一个学校,有3个办公室,现在有8位老师等待工位的分配,请编写程序,完成随机分配

posted @ 2020-06-18 18:56  ʚ追寻家ɞ  阅读(99)  评论(0编辑  收藏  举报