Python数据容器(五)
数据容器 数据容器是一类可以一次性存放多份数据的数据类型,存放的每一份数据称为 元素。元素的类型可以是任意 Python 数据类型(数字、字符串、布尔值、甚至其他容器)。 根据特性不同,Python 的数据容器分为五类: 列表(list) 元组(tuple) 字符串(str) 集合(set) 字典(dict) 示意图(页面 1 图片内容文字化): …
2025-12-06 22:45
|
103
|
|
Python函数使用(四)
函数基础 函数是“组织好、可重复使用、实现特定功能的代码段”。为了复用逻辑、减少重复代码、提高可维护性,我们会将可重复的逻辑封装成函数。 函数的完整格式 # 定义 def 函数名(传入参数): 函数体 return 返回值 # 使用 函数名(传入参数) 说明: 传入参数(形参)数量不限制 可以没有参数 也可以传入任意数量的参数 return 可写可…
2025-12-06 22:36
|
132
|
|
Python循环语句(三)
while 循环 while 循环用于在“条件满足”的前提下,重复执行代码。特点:条件为 True → 无限执行;条件为 False → 结束循环。 流程说明 判断条件 若条件为 是(True) → 执行操作 操作完成后再次回到条件处检查 若条件为 否(False) → 结束循环 此流程不断重复,形成循环结构。 定义格式 while 条件: 条件为…
2025-12-06 21:23
|
82
|
|
Python判断语句(二)
布尔类型 布尔类型用于表达现实生活中的逻辑,即“真”与“假”。 定义 Python 内置两个布尔字面量: True 表示真(是、肯定) False 表示假(否、否定) 补充说明: True 本质上等价于数字 1 False 本质上等价于数字 0 示例(定义布尔变量): name = True name = False 获取布尔类型的方式 布尔值可通…
2025-12-06 21:17
|
60
|
|
Python基础语法(一)
字面量 字面量指代码中被写下来的固定的值。 Python 中常用的 6 种值(数据)类型如下(此处重点了解前三种): Python 常用的数据类型表 类型(Type)描述说明数字(Number)支持:• 整数(int)• 浮点数(float)• 复数(complex)• 布尔(bool)整数(int),如:10、-10浮点数(float),如:13…
2025-12-06 21:12
|
72
|
|
C++实现游戏2048
用c++实现2048 #include<iostream> #include<random> #include<chrono> #include<conio.h> #define SIZE 4 using namespace std; //菜单 void Menu() { cout << "***********…
2025-11-28 16:32
|
77
|
|
C++学习案例记录&分享十二(通讯录系统)
此案例贯穿了基础编程的大部分知识点,最具代表性的案例 通讯录功能介绍 储存数据包括:姓名·性别·年龄·电话·住址 功能有:添加·查询·删除·修改·清空 代码展示 #include <iostream> #define Max 1000 using namespace std; //联系人结构体 struct Person { string m…
2025-11-28 16:26
|
73
|
|
c++爱心代码
#include <iostream> #include <string> #include <cstdio> #include <cmath> using namespace std; int main() { int c = 0; system("color 0c"); string str = "I love vick…
2025-11-28 16:21
|
67
|
|
C++学习案例记录&分享十一(结构体+冒泡排序)
结构体加冒泡排序的综合应用 #include <iostream> using namespace std; //创建英雄结构体 struct Hero { string name; int age; string gender; }; //创建冒泡排序函数 void bubbleSort(struct Hero array[], i…
2025-11-28 16:16
|
68
|
|
C++学习案例记录&分享十(结构体案例)
老师结构体下的学生子结构体 #include <iostream> #include <random> using namespace std; struct Student { string name; int score = 0; }; struct Teacher { string name; struct Student sAr…
2025-11-28 16:12
|
73
|
|