• Python


    1.python优点
    简单易学,开元免费,解释性语言,面向对象,功能强大,可扩展性,可移植性

    2.变量的类型
    数字,布尔类型,字符串,列表,元祖,字典

    3.标识符命名规则

    1.标识符由字母、下划线和数字组成,且不能以数字开头。
    2.Python中的标识符是区分大小写的
    3.Python中的标识符不能使用关键字
    4.见名知意
    5.命名按照大驼峰小驼峰方式命名


    4.如何在python中查找关键字
    cmd进入终端
    输入python
    输入import keyword
    输入keyword.kwlist

    5.常用的格式符号有哪些(3个即可)
    %s 通过str() 字符串转换来格式化
    %c 字符
    %d 有符号十进制整数
    %f 浮点实数

    6.运算符(至少5个)
    + 加
    - 减
    * 乘
    / 除
    % 取模 - 返回除法的余数
    ** 幂 - 返回x的y次幂
    // 取整除 - 返回商的整数部分(向下取整)


    7.python常用的数据类型转换(至少3个

    8.计较运算符(至少3个)

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

    and or not
    
    
    10.自己写一个if-elif-else条件语句并输出
    猜拳判断:
      

        

    print("0石头1剪刀2布")
    wan1=int(input("玩家一的回合:"))
    wan2=int(input("玩家二的回合:"))
    if (wan1>=0 and wan2<=2)and(wan1<=2 and wan2>=0):
    if (wan1==0 and wan2==1)or(wan1==1 and wan2==2)or(wan1==2 and wan2==0):
    print("玩家一获胜!!")
    elif wan1==wan2:
    print("平局!!")
    else:
    print("玩家二获胜!!")
    else:
    print("参数错误")
    11.通过程序写一个等边三角形
    while方法:
      
    a = 1
    while a <= 6:
    print("*" * a)
    a += 1
    for方法:
     
    for i in range(1,6):
    print("*" * i)
    
    
    12.通过程序写一个九九乘法表
    while方法:
    a=1
    while a<=9:
    b=1
    while b<=a:
    print("%d * %d=%d"%(b,a,b*a),end=" ")
    b+=1
    print()
    a+=1


    for方法:

    for i in range(1,10):
    for b in range(1,i+1):
    print("%d * %d =%d"%(b,i,b*i),end=" ")
    print()


    13.通过代码针对str="abcdefg"  :
    1取出bcd
    2将str倒序
    3取出bdf
    str='abcdefg'
    c = str[1::2]
    print(c) #bdf

    14.通过代码针对mystr = "hello world python and python"进行如下操作
    1.找到右边第一个p的索引
      
        a = mystr.rfind('p')

    2.找z结果要求报错

        
        b = mystr.index('z')

    3.将所有空格替换成逗点
        mystr2 = mystr.replace(' ',',')

    4.通过逗点生成一个列表
        mystr2 = mystr.replace(' ',',')
        alist = mystr2.split(',')

    5.将d全部替换成大写D
        mystr2 = ''
        for i in mystr:
        if i == 'd':
        i = i.upper()
         print(i)
        mystr2 += i
        print(mystr2)
    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)
    a.append('我心态炸了')
    a.remove(1)

    16.b = ["a","b","c","b","a"] 
    查找索引区间在2-4的“b”的索引
    查找索引区间在3-4的“a”的索引
    b = ["a","b","c","b","a"]
    n = b.index('b',2,4)
    n = b.index('a',3,4)
    17.自己写一个字典,计算自己写的字典中存在键值对的个数,找出字典中所有的key,找出字典中所有的value,试着遍历字典中的item,最后删除字典中的第一个键所对应的数据
    a = {'name':'王五','age':18,'sex':'男'}
    print(a.__len__())
    print(a.keys())
    print(a.values())
    for i in a.items():
    print(i)
    del a['name']
    print(a)

    18.集合中的discard的概念

    discard() 方法用于移除指定的集合元素。
    该方法不同于 remove() 方法,因为 remove() 方法在移除一个不存在的元素时会发生错误,而 discard() 方法不会。
    语法:
    set.discard(value)
     
    19.试着自己写两个集合,分别进行 & 和 | 的操作
     
    set1 = {'李四',123,'a'}
    set2 = {'张三',123,'b'}
    print(set1&set2)
    print(set1|set2)





  • 相关阅读:
    Centos7 yum缓存rpm安装包 规格严格
    基于postgresql行级锁for update测试 规格严格
    Web安全 Acunetix漏洞扫描工具.(破解版) 规格严格
    PostgreSQL 数组(Array) 规格严格
    oracle恢复broken的job,Oracle JOB异常中断原因分析 规格严格
    Eureka 与 zookeeper 的区别、原理及各自优缺点 规格严格
    Appenders 规格严格
    在windows下使用s3cmd和s3browser来管理amazon s3的笔记
    [python][flask] Flask 图片上传与下载例子(支持漂亮的拖拽上传)
    【转】评估分类模型的指标:ROC/AUC
  • 原文地址:https://www.cnblogs.com/qin-shi-wei/p/13160810.html
Copyright © 2020-2023  润新知