zoukankan      html  css  js  c++  java
  • 2019.9.10作业

    1. 简述Python的五大数据类型的作用、定义方式、使用方法:

      1. 数字类型

        整型(int)

        作用:表示整数

        定义方式:a = 1或a = int(1)

        使用方法:+ - * / ** // %

        浮点型(float)

        作用:表示小数

        定义方式:a = 1.123或a = float(1.123)

        使用方法:+ - * / ** // %

      2. 字符串类型

        作用:描述一下东西

        定义方式:'' "" '''''' """""" 或s = str('')

        使用方法:+ *

      3. 列表

        作用:描述一连串东西的表格

        定义方式:ls = [] 或ls = list(iterable)

        使用方法:+ 索引

      4. 字典

        作用:定key查找一系列数据

        定义方式:dic = {key1:value1,key2:value2,......}

        使用方法:按key取值

      5. 布尔型

        作用:对特定代码进行判断True False

        定义方式:int型子类

        使用方法:判断

    2. 一行代码实现下述代码实现的功能:

    x = 10
    y = 10
    z = 10
    
    x = y = z = 10
    
    1. 写出两种交换x、y值的方式:
    x = 10
    y = 20
    
    z = x
    x = y
    y = z
    
    x,y = y,x
    
    1. 一行代码取出nick的第2、3个爱好:
    nick_info_dict = {
    'name':'nick',
    'age':'18',
    'height':180,
    'weight':140,
    'hobby_list':['read','run','music','code'],
    }
    
    print(nick_info_dict['hobby_list'][1],nick_info_dict['hobby_list'][2])
    
    1. 使用格式化输出的三种方式实现以下输出(name换成自己的名字,既得修改身高体重,不要厚颜无耻)
    name = 'Nick'
    height = 180
    weight = 140
    
    # "My name is 'Nick', my height is 180, my weight is 140"
    

    占位符

    name = 'Agsol'
    height = 226
    weight = 160
    print("My name is '%s', my height is %d, my weight is %d"% (name,height,weight))
    

    .format

    name = 'Agsol'
    height = 226
    weight = 160
    print("My name is '{}', my height is {}, my weight is {}".format(name,height,weight))
    

    f-string

    name = 'Agsol'
    height = 226
    weight = 160
    print("My name is '{}', my height is {}, my weight is {}".format(name,height,weight))
    
  • 相关阅读:
    Chapter1-data access reloaded:Entity Framework(上)
    Part1-Redefining your data-access strategy 重新定义你的数据访问策略
    ora-12541无监听的一种场景
    GridView根据一列自动计算(转载)
    百度Fex webuploader.js上传大文件失败
    JS文件中引用另一个JS文件
    连接虚拟机的SQLServer
    Spring中Bean的生命周期
    Spring中Bean的作用范围调整
    Spring中三种创建Bean对象的方式
  • 原文地址:https://www.cnblogs.com/agsol/p/11497781.html
Copyright © 2011-2022 走看看