首页 > 编程语言 >笨办法学Python3 习题32 循环和列表

笨办法学Python3 习题32 循环和列表

时间:2023-10-11 21:22:22浏览次数:36  
标签:count Adding 笨办法 32 list Element 习题 列表 was

知识点:

  • for  i  in  y :  # for循环开始 i 变量就被创建,所以不用提前创建
  • 只有在for 循环里有效
  • range(,)函数会从第一个数到最后一个之前的数,不包含最后一个数
  • Y.append(X) 将X 追加到列表Y的尾部
 1 the_count = [1,2,3,4,5]                      # 创建3个列表变量
 2 fruits = ['apples','orange','pears','apricots']
 3 change = [1,'pennies',2,'dimes',3,'quarters']
 4 
 5 for number in the_count:                     # 循环第一个列表
 6     print(f"This is count {number}")
 7 
 8 for fruit in fruits:
 9     print(f"A fruit of type : {fruit}")      # 循环第二个列表
10 
11 for i in change:                             # 循环第三个列表
12     print(f"I got {i}") 
13     
14 elements = []                                # 循环外创建空列表
15 
16 for i in range(2,15):                        # range()函数会从第一个数到最后一个之前的数,不包含最后一个数
17     print(f"Adding {i} to the list.")     
18     elements.append(i)                       # i 进行循环的同时,空列表尾部追加 i
19 
20 for i in elements:                           # 用循环查看之前的空列表是否被复制好填完整
21     print(f"Element was : {i}")
PS C:\Users\Administrator\lpthw> python ex32.py
This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
A fruit of type : apples
A fruit of type : orange
A fruit of type : pears
A fruit of type : apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
Adding 2 to the list.
Adding 3 to the list.
Adding 4 to the list.
Adding 5 to the list.
Adding 6 to the list.
Adding 7 to the list.
Adding 8 to the list.
Adding 9 to the list.
Adding 10 to the list.
Adding 11 to the list.
Adding 12 to the list.
Adding 13 to the list.
Adding 14 to the list.
Element was : 2
Element was : 3
Element was : 4
Element was : 5
Element was : 6
Element was : 7
Element was : 8
Element was : 9
Element was : 10
Element was : 11
Element was : 12
Element was : 13
Element was : 14

 

标签:count,Adding,笨办法,32,list,Element,习题,列表,was
From: https://www.cnblogs.com/luxiaoli/p/17758223.html

相关文章

  • 关于CH32V系列MCU中断优先级配置以及硬件压栈
    从下图可以看出,第二列与第三列分别为优先级与优先级类型,优先级类型又分为两种,其一是固定优先级,其二是可编程的优先级。以RTC为例,优先级为5,优先级类型为可编程,代表着在不配置RTC的优先级时默认为5,如果需要,也可以将其配置为更高的优先级进行响应。下图关于中断优先级配置,针对CH32V......
  • 关于CH32V系列MCU 免表中断(VTF)的使用配置方法
    可编程快速中断控制器(PFIC)提供四个免表(VectorTableFree)中断通道,可不经过中断向量表的查表过程,直达中断函数入口。个人简单测试过,当开启VTF后,中断延迟时间大概可缩短2个时钟周期左右。关于VTF的具体介绍,可参考对应青稞微处理器手册3.5小节。QingKeV3手册:https://www.wch.cn/do......
  • python32days
    异常元类—————————————————————————————————————————————异常就是错误发生的信号,我们需要对该信号做处理,如果不处理,往后的代码就不能执行了异常的分类 逻辑错误#是允许出现的,但是呢,编程的时候尽量避免逻辑错误的发生语法错......
  • 关于CH32V307 PA6、7引脚复用为串口1和串口7配置方法
    1、复用为串口1配置方法关于PA6和PA7,重映射串口1时,最后下标为3,如下图。换算成二进制为11,重映射对应的就是PA6、PA7,如下图。由于库中没有直接定义该位,因此将PA6、PA7复用为USART1时,需要进行如下操作,如下图。可直接调用GPIO_PinRemapConfig函数,先调用该函数复用为USART1高位,再......
  • win32汇编-调用API
      Win32API是用堆栈来传递参数的,调用者把参数一个个压入堆栈,DLL中的函数程序再从堆栈中取出参数处理,并在返回之前将堆栈中已经无用的参数丢弃。在Microsoft发布的《MicrosoftWin32Programmer'sReference》中定义了常用API的参数和函数声明,先来看消息框函数的声明:......
  • STM32---I2C通讯
    STM32的I2C通讯可以使用两种方式实现,分别是软件I2C,和硬件I2C。软件I2C主要是通过代码手动翻转电平来模拟时序;硬件I2C主要使用通过STM32自带的硬件外设实现。以下,我着重讲述一下硬件I2C的部分。 想要使用硬件I2C,主要分为以下四个步骤:第一步,开启GPIO和I2C的时钟跟GPIO一样,I2C需......
  • ESP32
    目录模组分类(选型)相关资料模组分类(选型)系列内核主频功能数据手册ESP32-S2Xtensa单核240MHz2.4GHzWi-FiESP32-S2DataSheetESP32-S3Xtensa双核240MHz2.4GHzWi-FiBluetooth5(LE)ESP32-S3DataSheetESP32-C2RISC-V单核120MHz2.4GHzW......
  • STM32关闭全局中断时需要注意的问题
       STM32在使用时有时需要禁用全局中断,比如MCU在升级过程中需禁用外部中断,防止升级过程中外部中断触发导致升级失败。ARMMDK中提供了如下两个接口来禁用和开启总中断:__disable_irq();  //关闭总中断__enable_irq();   //开启总中断      但测试发现这样一......
  • 【ABC320C】题解
    AtCoderBeginnerContest320ProblemC-SlotStrategy2(Easy)题解题目简述给定\(3\)个长度为\(m\)的转盘,转动过后三个转盘分别可以在不同的时间停下,求停下时所有转盘都显示相同数字的最小时间。思路由于这题\(m\le100\),数据较水,所以可以先把每个数列都复制\(......
  • 【ABC320D】题解
    AtCoderBeginnerContest320ProblemD-RelativePosition题解题目保证不矛盾,就可以直接vector建图,然后dfs一遍,边权为\((w_x,w_y)\)表示坐标的差,从\(u=1\)开始搜索,设点\(u,v\)有一条无向边,\(v_x=u_x+w_x,v_y=u_y+w_y\),最后如果没有被标记过的话(也就是没有......