(Datacamp)从零开始学python(1)——basics and lists

本文介绍了Python的基础知识,包括数据类型如布尔型、整型/浮点型、字符串和列表等。详细讲解了列表的操作方法,例如索引访问、子集获取及元素删除。此外还涵盖了数据类型转换和基本运算等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python(1)

(1)数据类型

  • booleans
  • int/float
  • str
  • list

list 的使用
areas=[11,22,33,44,55]
————0 1 2 3 4
_______-5 -4 -3 -2 -1

(1)
areas[0]=11
areas[-1]=55
print(2:4) :输出a[2],a[3],左闭右开
print(:2):自动视作左边为a[0],会输出11,22
! print(2:):也会输出55,不写的话最后一个也会被包括

(2)子集

   x = [["a", "b", "c"],
     ["d", "e", "f"],
     ["g", "h", "i"]]
    print(x[2][0])

输出结果是d

(3)数组中元素的删除
areas = [“hallway”, 11.25, “kitchen”, 18.0,“chill zone”, 20.0, “bedroom”, 10.75,
“bathroom”, 10.50, “poolhouse”, 24.5, “garage”, 15.45]
想删掉areas[-4:-2]的元素
但若是直接输入del (areas[-3],areas[-4])或者del(areas[10:11])无法实现
因为是逐个删除的,这样的话删掉了24.5后,poolhouse就变成了areas[-3]

(4)数组中元素的变动——Inner workings of lists
在这里插入图片描述
阻止图一中的变动可以使用list() or [:].

(2)数据类型的转换
input:

income = 30.23
print("I managed to get  $“+str(income) +"this month.")

output:

I managed to get  $30.23 this month.

(3)运算

  • **: 幂运算
  • / :求模运算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值