Python 基础性知识点及操作题.docx
![preview](https://dl-preview.csdnimg.cn/88215338/0001-1691aaff05e97bee33ceee1c67dacc94_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
Python是一种广泛使用的高级编程语言,尤其适合初学者入门。它以其简洁明了的语法和强大的功能而闻名。以下是一些Python基础性知识点的详细说明: 1. **字符串**: - 切片和索引:`x[3]` 返回字符串的第四个字符,`x[-2]` 返回倒数第二个字符,`x[2: -2]` 截取从第三个字符到倒数第三个字符之间的子串。 - `count()` 方法统计子串出现的次数,如`x.count('l', 3, 9)` 计算从第3个字符到第9个字符范围内'l'出现的次数。 - `find()` 和 `index()` 方法查找子串,前者找不到返回-1,后者找不到会抛出异常。 2. **列表**: - 列表可以通过索引访问,如`list[1]` 获取第二个元素。 - `append()` 方法在末尾添加元素,`list.append("d")` 添加'd'。 - `insert()` 方法在指定位置插入元素,`list.insert(1, "e")` 在第二个位置插入'e'。 - `remove()` 方法删除指定元素,`list.remove("c")` 删除'c'。 - `pop()` 方法移除并返回列表最后一个元素,`list.pop()` 移除'd'。 3. **元组**: - 元组不可变,元素个数通过`len(tuple)`获取,如`len(("a", "b", "c", "d"))`。 - 元组可以通过索引访问,但不能修改或删除元素。 4. **字典**: - 访问字典元素用`dict["key"]`,如`dict["b"]`。 - `dict[key] = value` 直接添加或修改元素。 - `del(dict[key])` 删除元素。 - `dict.pop(key)` 删除并返回元素。 5. **函数**: - 定义函数:`def function_name(parameters):`,如`def product2num(x, y):` 计算乘积。 - 调用函数:`function_name(args)`,如`a = product2num(2, 6)`。 6. **控制流**: - 用户输入:使用`input()`函数,如`num1 = int(input("请输入第 1 个整数:"))`。 - 字符串操作:`str1[下标]`获取字符,`str1[m:n:k]`切片,`len(str1)`获取长度,`int(str1)`转为整数,`str(num1)`转为字符串。 7. **编程题**: - 题目要求涉及字符串截取、条件判断等,实现逻辑通常需要结合上述知识点。 8. **日期和时间**: - 使用`import time`库,`time.strftime(format)`格式化日期和时间。 以上就是Python基础知识的一部分,包括字符串操作、列表和元组的使用、字典的管理、函数的定义和调用,以及基本的字符串和控制语句。对于初学者来说,熟练掌握这些概念和操作是学习Python的基础。在实际编程中,还需要学习更多的内容,如文件操作、模块导入、异常处理、面向对象编程等,以构建更复杂的程序。
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/release/download_crawler_static/88215338/bg1.jpg)
![](https://csdnimg.cn/release/download_crawler_static/88215338/bg2.jpg)
![](https://csdnimg.cn/release/download_crawler_static/88215338/bg3.jpg)
![](https://csdnimg.cn/release/download_crawler_static/88215338/bg4.jpg)
剩余20页未读,继续阅读
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/9c7e30ca8e3c4387bc6a3c338334c783_weixin_41234946.jpg!1)
- 粉丝: 81
- 资源: 9
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- python-leetcode面试题解之第401题二进制手表.zip
- python-leetcode面试题解之第400题第N位数字.zip
- python-leetcode面试题解之第392题判断子序列.zip
- python-leetcode面试题解之第389题找不同.zip
- python-leetcode面试题解之第388题文件的最长绝对路径.zip
- python-leetcode面试题解之第387题字符串中的第一个唯一字符.zip
- 数据库课程设计on-model-for-netwo开发笔记
- linux常用命令大全mage-processing-m开发笔记
- mysql安装配置教程droid-m开发笔记
- PWMmodel-for-network-ids-ma开发笔记
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)