zoukankan      html  css  js  c++  java
  • day 04

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

    1.1 数字类型

    作用:描述年龄/id号

    定义方式:

    tjx_age = 22
    print(tjx_age)
    

    使用方法:

    x = 1
    y = 2
    print(x + y)
    print(x - y)
    print(x * y)
    print(x / y)
    

    1.2 字符串类型

    作用:描述姓名/单个爱好/性别

    定义方式:

    name = 'tjx'
    name = "tjx's"
    name = "tjx"
    name = '''
    tjx
    '''
    name = """
    tjx"""
    

    使用方法

    str1 ='t'
    str2 = 'z'
    print(str1+str2)
    print(str1*10)
    

    1.3 列表

    作用:存储多个(任意数据类型)元素

    定义方式:

    num = 0
    s = ''
    it = []
    lis = []
    

    使用方法:

    tjx_hobby_list = ['run','music','read',172,110]
    print(tjx_hobby_list[1])
    print(tjx_hobby_list[4])
    print(tjx_hobby_list[-1])
    

    1.5 布尔型

    作用:用于判断条件结果

    定义:True、False通常情况不会直接引用,需要使用逻辑运算得到结果。

    使用方法:

    print(type(True)
    print(True)
    
    <class 'bool'
    True
    
    print (bool(0))
    print(bool('tjx'))
    print(bool(1 > 2))
    print(bool(1 == 1))
    
    False
    True
    False
    True
    

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

    x = 10
    y = 10
    z = 10
    
    print(x,y,z)
    

    3 .写出两种交换x、y值的方式:

    x = 10
    y = 20
    
    z = y
    y = x
    x = y
    print(x,y)
    
    x,y = y,x
    print(x,y)
    

    4.一行代码取出nick的第2、3个爱好

    nick_info_dict = {
    'nick':'nick',
    'age':'18'
    'height':180,
    'weight':140,
    'hobby_list':['read','run','music','code'],
    }
    
    print(hobby_list[1][2])
    

    5. 使用格式化输出的三种方式实现一下输出

    name = 'tjx'
    height = 172
    weight = 110
    
    # "My name is'tjx',my height is 172, my weight is 110"
    
    print('my name is %s my height is %s my weight is%s' %(name, height,weight))
    
    my name is tjx my height is 172 my weight is 110
    
    print("hello,{}. {}.{}. ".format(name, height, weight))
    
    hello, tjx. 172.110
    
    print(f"hello,{name}.You are {height}.You are {weight}")
    
    hello,tjx.You are 172.You are 110
    
  • 相关阅读:
    Maximum sum-动态规划
    Ubuntu14下Hadoop开发&lt;1&gt; 基础环境安装
    POJ 3252 Round Numbers 数学题解
    ubuntu环境 rake aborted!
    oracle decode函数用法
    Android多线程研究(1)——线程基础及源码剖析
    2014冬去春来
    Android中的动画详解系列【4】——Activity之间切换动画
    JavaScript你所不知道的困惑(3)
    研发人员技术定级的一些思考
  • 原文地址:https://www.cnblogs.com/TZ0503/p/11498389.html
Copyright © 2011-2022 走看看