pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

“消費"是什么意思?在 Python 中?在迭代器中

What does it mean to quot;consumequot; in Python? In an iterator?(“消費是什么意思?在 Python 中?在迭代器中?)
本文介紹了“消費"是什么意思?在 Python 中?在迭代器中?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經在 Python 中工作了幾個月,我突然想到,我經常忽略乍看之下無法理解的詞匯,而是試圖了解一個想法的要點.現在回想起來,我仍然對consume這個詞的含義感到困惑.我最初的興趣來自對迭代器的解釋,它談到了正在消耗的迭代器的值.但是,環顧四周,這在 Python 詞典中似乎并不常見.或者是嗎?在這里挖掘發現主要是對 Web 服務的引用,以及關于如何隱藏函數的這個或那個結果的一兩個討論.

I have been working in Python for a few months now, and it has occurred to me that I often overlook vocabulary that escapes me at first glance, instead trying to get the gist of an idea. Now, looking back, I still find myself confused beyond belief at what the term consume refers to. My initial interest came from explanations of iterators which spoke of a value of an iterator being consumed. However, looking around, this does not seem to be commonplace in the Python lexicon. Or is it? Digging around here finds mostly references to Web Services, and one or two discussions on how to hide this or that result of a function.

我想,把我的無知分解成幾個基點:

I suppose then, to break down my ignorance into a few base points:

  1. 消費"在不同的 Python 語境中會做不同的事情嗎?
  2. 數據在被消費時會發生什么,例如在 iter() 中?
  3. 當一個變量被分配給一個迭代器的結果(據稱是消耗的數據)時,它是否不再屬于迭代器?
  4. 您能否在一次調用迭代器時從迭代器對象中使用多個值?

我希望這有點道理.請注意,這不是針對任何特定需求;我只是感到困惑,超出了合理的合理性.

I hope that makes some sort of sense. Note that this is not in reference to any particular need; I'm simply confused beyond rational plausibility.

還有一件事......迭代值(當使用 next() 調用時)是否保留在內存中?

One more thing... does an iterated value (when called with next()) stay in memory?

推薦答案

關于 2.

事實上,我們必須區分兩種情況.

In fact, we must distinguish two cases.

記住 Greg Hewgill 寫的:

Remember what Greg Hewgill wrote:

迭代器"是負責的單個對象用于創建一些元素序列.這個序列可能是現有列表的元素,或者它可能是計算出來的,比如素數或π的小數位.

An "iterator" is a single object that is responsible for creating some sequence of elements. This sequence might be elements of an existing list, or it might be something calculated, like prime numbers or the decimal digits of π.

第一種情況:

迭代器計算受刺激時它必須產生的對象;也就是說,在調用 next() 之前,生成的對象并不存在.因此,如果為對象分配了名稱,則后者將繼續存在;如果不是,則該對象會在一定時間內不與命名空間中的名稱綁定而存在,然后它將在內存中消失,也就是說它所占用的位將在以后或早日用于另一個對象.

the iterator calculates the object that it must produce when stimulated; that is to say, the produced object wasn't existing before the call of next() . Consequently, if a name is assigned to the object, this latter will survive; if not , the object will exist without being binded to a name in a namespace during a certain time, and then it will vanish in the memory, that is to say the bits it occupies will be used for another object later or sooner.

第二種情況

是當迭代器返回以前存在的屬于列表、元組、字典等的對象時.在這種情況下,由 next() 生成的每個對象已經與名稱.然后,如果對象在彈出"迭代器時被分配了一個新名稱,那么將有兩個名稱綁定到該對象.如果對象沒有被分配一個名字,它會繼續只綁定一個名字,這足以維持對象的存活.

is when the iterator returns formerly existing objects belonging to a list, a tuple, a dictionary, etc.. In this case, each object produced by a next() had already a binding with a name. Then if the object is assigned to a new name when it "pops" out of the iterator, there will be two names binded to the object. And if the object is not assigned to a name, it will continue to be binded to only one name, what is sufficient to maintain the object alive.

共同點:

每次調用迭代器生成對象時,如果沒有為其分配名稱,則操作的唯一結果是迭代器已被消費".這是一種說法,即使在生成對象后沒有永久性后果,它也發生了一些在迭代器內部留下痕跡的事情.

Each time an object is produced by a call of an iterator, if no name is assigned to him, the only result of the operation is that the iterator has been "consumed". It's a manner to say that even if there is no permanent consequence after the production of an object, it has happened something that let a trace inside the iterator.

也有人說在為對象分配名稱時使用迭代器,但是,我不想混淆.

One speaks of consuming the iterator when a name is assigned to the object, too, however, I don't want to confuse.

注意:

事實上,如果一個對象預先存在于一個列表中,比如說,它可能沒有名字.但是列表包含了它包含"的每個對象的引用……事實上,列表并不包含"對象,而只是對對象的引用……這超出了我想說的范圍.

In fact, in case of an object pre-existing in a list, say, it may be that it had no name. But the list holds a reference of every object it "contains"... In fact a list doesn't "contains" objects, but only references to objects... Well that goes beyond what I wanted to say.

.

關于3

你不應該寫3:當一個變量被賦值給..."

變量這個詞在 Python 中是一個陷阱,因為它的含義不明確.Python 中沒有變量,在其他語言中的常識中,即 ? 值可以改變的內存的分隔部分?.只有對象.變量這個詞習慣性地用來表示一個標識符.因此,最好將其稱為 identifiername.這樣可以避免混淆.

The word variable is a pitfall in Python because it has an ambiguous signification. There are no variables in Python, in the common sense known in other langages, that is to say a ? delimited portion of memory whose value can change ?. There are only objects. The word variable is habitually used to mean an identifier. So it is a better practice to call it identifier, or name. This avoids confusion.

.

關于4

我認為只有一次調用 next()

這篇關于“消費"是什么意思?在 Python 中?在迭代器中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 强效碱性清洗剂-实验室中性清洗剂-食品级高纯氮气发生器-上海润榕科学器材有限公司 | 老房子翻新装修,旧房墙面翻新,房屋防水补漏,厨房卫生间改造,室内装潢装修公司 - 一修房屋快修官网 | 上海宿田自动化设备有限公司-双面/平面/单面贴标机 | 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | 中药二氧化硫测定仪,食品二氧化硫测定仪|俊腾百科| 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂_帽子厂_浙江高普制帽厂 | ASA膜,ASA共挤料,篷布色母料-青岛未来化学有限公司 | 冷镦机-多工位冷镦机-高速冷镦机厂家-温州金诺机械设备制造有限公司 | 金联宇电缆|广东金联宇电缆厂家_广东金联宇电缆实业有限公司 | 金属清洗剂,防锈油,切削液,磨削液-青岛朗力防锈材料有限公司 | 济南保安公司加盟挂靠-亮剑国际安保服务集团总部-山东保安公司|济南保安培训学校 | 原子吸收设备-国产分光光度计-光谱分光光度计-上海光谱仪器有限公司 | 气象监测系统_气象传感器_微型气象仪_气象环境监测仪-山东风途物联网 | 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 空气能暖气片,暖气片厂家,山东暖气片,临沂暖气片-临沂永超暖通设备有限公司 | 阀门智能定位器_电液动执行器_气动执行机构-赫尔法流体技术(北京)有限公司 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 天津云仓-天津仓储物流-天津云仓一件代发-顺东云仓 | 智成电子深圳tdk一级代理-提供TDK电容电感贴片蜂鸣器磁芯lambda电源代理经销,TDK代理商有哪些TDK一级代理商排名查询。-深圳tdk一级代理 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 民用音响-拉杆音响-家用音响-ktv专用音响-万昌科技 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 1000帧高速摄像机|工业高速相机厂家|科天健光电技术 | 无缝方管|无缝矩形管|无缝方矩管|无锡方管厂家| 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 胶原检测试剂盒,弹性蛋白检测试剂盒,类克ELISA试剂盒,阿达木单抗ELISA试剂盒-北京群晓科苑生物技术有限公司 | 千斤顶,液压千斤顶-力良企业,专业的液压千斤顶制造商,shliliang.com | 劳动法网-专业的劳动法和劳动争议仲裁服务网 | 运动木地板价格,篮球馆体育运动木地板生产厂家_欧氏地板 | 罗茨真空机组,立式无油往复真空泵,2BV水环真空泵-力侨真空科技 | 纯水电导率测定仪-万用气体检测仪-低钠测定仪-米沃奇科技(北京)有限公司www.milwaukeeinst.cn 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 手术室净化装修-手术室净化工程公司-华锐手术室净化厂家 | SOUNDWELL 编码器|电位器|旋转编码器|可调电位器|编码开关厂家-广东升威电子制品有限公司 | 散热器厂家_暖气片_米德尔顿散热器| HEYL硬度计量泵-荧光法在线溶解氧仪-净时测控技术(上海)有限公司 | 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 成都治疗尖锐湿疣比较好的医院-成都治疗尖锐湿疣那家医院好-成都西南皮肤病医院 | 珠光砂保温板-一体化保温板-有釉面发泡陶瓷保温板-杭州一体化建筑材料 | 酒吧霸屏软件_酒吧霸屏系统,酒吧微上墙,夜场霸屏软件,酒吧点歌软件,酒吧互动游戏,酒吧大屏幕软件系统下载 |