ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python学习笔记1

2022-01-26 19:04:30  阅读:103  来源: 互联网

标签:__ python float 笔记 学习 str time print type


1、python中的数据类型

Numbers(数字)、 String(字符串)、 List(列表)、 Tuple(元组)、 Dictionary(字典)

Numbers(数字)

number数字类型里面又包含四种类型:int整形、float浮点型、bool布尔值。int整形包含正整数、负整数和0;float浮点型就是小数形式;bool布尔值是True和False。我们可以用type检查数字类型

布尔值非0即为True

#春游小案例
title = '春游活动'
class_count = 51
boys = 28
girls = 23
every_pay = 35.5
start_time = 8.00
bus_count = 2
site_every_bus = 30
come_park_time = 10.33
have_lunch = 12.00
lunch_pay = 25.5
leave_park_time = 3.05
bus_pay = 5
leave_school_time = 5.00
back_pay = 5

if __name__ == '__main__':
    print(title)
    print('title的类型是:',type(title))
    print(f'春游人数有:{class_count}人,男生人数有:{boys}人,女生人数有:{girls}人,每人需要支付:{every_pay}元')
    print('class_count的类型是:',type(class_count))
    print(f'出发时间:{start_time},大巴士数量:{bus_count},大巴士座位数量:{site_every_bus}')
    print('start_time的类型是:',type(start_time))
    print('bus_count的类型是:',type(bus_count))
    print('到达公园的时间:', come_park_time)
    print(f'吃午饭时间:{have_lunch},午饭金额:{lunch_pay}元')
    print(f'离开公园的时间:{leave_park_time},公交车费:{bus_pay}元')
    print(f'离开学校时间:{leave_school_time}')
    print(f'最终返还:{back_pay}元', )

String(字符串)

字符串就是用单引号‘’或者双引号“”括起来的任意字符

str_1 = ''
str_2 = ""
str_3 = '111'
str_4 = '"123","aaa"'
str_5 = '[123]'
str_6 = 'float'
str_7 = 'true'
if __name__ == '__main__':
    print('str_1的类型是:',type(str_1))
    print('str_2的类型是:', type(str_2))
    print('str_3的类型是:', type(str_3))
    print('str_4的类型是:', type(str_4))
    print('str_5的类型是:', type(str_5))
    print('str_6的类型是:', type(str_6))
    print('str_7的类型是:', type(str_7))

List(列表)

List(列表) 是 Python 中使用最频繁的数据类型,一般使用[ ]标识。

float_1 = [123]
float_2 = []
float_3 = ['hjjkkk']
float_4 = [[111],[222],[333]]

if __name__ == '__main__':
    print('float_1的类型是:',type(float_1))
    print('float_2的类型是:', type(float_2))
    print('float_3的类型是:', type(float_3))
    print('float_4的类型是:', type(float_4))

Tuple(元组)

元祖使用与列表类似,可以使用一些序列进行组合,但是组合之后不能修改,元祖中的数据和列表一样,使用英文逗号隔开。元祖一般使用()标识,元祖也可以用空()标识,但是如果里面有数据就需要使用英文逗号,隔开,否则会出错

Dictionary(字典)

 

标签:__,python,float,笔记,学习,str,time,print,type
来源: https://blog.csdn.net/m0_62462239/article/details/122695894

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有