python学习笔记1

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(元组)

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

str_touple = ('123', 'sdfg', '')
int_touple = (1, 2, 3, 4, 5, 6, 7)
float_touple = (3.14526, 2.3, 5.95)
bool_touple = (True, False)
none_touple = (None, None, None)
touple_touple = ((1,2,3),(2,5,6))
list_touple = ([1,2,3],[5.6])
if __name__ == '__main__':
    print('str_touple的类型是:', type(str_touple))
    print('int_touple的类型是:', type(int_touple))
    print('float_touple的类型是:', type(float_touple))
    print('bool_touple的类型是:', type(bool_touple))
    print('none_touple的类型是:', type(none_touple))
    print('touple_touple的类型是:', type(touple_touple))
    print('list_touple的类型是:', type(list_touple))

 Dictionary(字典)

字典是由多个key(键)value(值)对应组成的,通常用{  }组成

字典支持的数据类型

key支持字符串,数字和元祖类型,但列表不支持

value支持所有的数据类型

a = {'name':'张三',"age":"20"}
b = {1:"one",2:"two"}
dict_array = [{1:1,2:2},{1:"one",2:"two"}]
dict_touple = ({1:1,2:2},{1:"one",2:"two"})

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值