嵌入式+人工智能学习记录

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

嵌入式+人工智能学习记录。


一、20231126_python学习

1.字典
2.字符串

二、学习代码

1.字典

代码如下(示例):

# 字典
webstersDict={'marathon': 'a running race that is about 26 miles',
 'person': 'a human being, whether an adult or child',
 'resist': ' to remain strong against the force or effect of (something)',
 'run': 'to move with haste; act quickly'}
# 字典访问
print(webstersDict['marathon'])
# 字典添加
webstersDict.update({'shirt': 'a long- or short-sleeved garment for the upper part of the body',
 'shoe': 'an external covering for the human foot, usually of leather and consisting of a more or less stiff or heavy sole and a lighter upper part ending a short distance above, at, or below the ankle.'})
print(webstersDict)
# 字典删除
del webstersDict['marathon']
print(webstersDict)
# 字典中有run,则显示,若无,print0
print(webstersDict.get('run1',0))
# .pop删除字典元素,count返回弹出的这个元素
count = webstersDict.pop('run')
print(count)   #to move with haste; act quickly
print(webstersDict)# webstersDict---少了run

# 遍历key或者value,或者一起遍历
# return keys in dictionary
print(webstersDict.keys())

# return values in dictionary
print(webstersDict.values())

# storyCount
# # iterate through keys
for key in webstersDict:
    print(key)

# # iterate through keys and values
for key, value in webstersDict.items():
    print(key, value)

2.字符串

代码如下(示例):

对字符串的操作方法, .lower() .upper() .title()分别表示小写,大写,标题格式
先创建变量在进行操作
help()用来查找方法的使用方法
分离字符串firstVariable.split(" ") firstVariable.split(‘  ’) firstVariable.split()结果相同
             a=firstVariable.split(' ')
                    a  a是新变量,没有改变firstVar
' '.join(a) 与split功能相反
print("0" + "1") ======= 字符串连接,结果没有‘’
"Fizz" + "Buzz"也是字符串连接 
min(z), max(z), len(z), sum(z)列表的最大值, 最小值, 长度, 以及总和
Var.count(1) count方法确定数字1出现次数
Var.index(1) index方法确定数字1出现第一次的索引号,即位置
Var..index(4, 3) 4是数字,3是开始处理的索引号
Var..index(4, 5, 6) 4是数字,56是开始和结束处理的索引号
a.sort()正排序,数字小大,字母顺序
x.sort(reverse = True) 反排序,数字大小,字母反顺序
y=sorted(x) y是排序后的a,a未变
a.append(3) 列表末尾加一个数3
a.remove(10) 删除确定数字
a.pop(3) 删除确定位置的元素
a.extend([4, 5]) 延长列表,添加了45
print('x+y=',x+y)合并xy两个列表
a.insert(4, [4, 5])在索引4的位置添加【4,5

总结

作为嵌入式与人工智能学习的记录。字符串和字典使用比较频繁。
提示:这里参考了:https://blog.csdn.net/qq_41271475/article/details/118544095

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值