In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what the usage of yield is, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Let's take a look at the exercises related to the two generators, mainly to practice the use of yield.
Question 1
Enter a number n, write a program to determine the even number between 0 and n, and separate the output with a comma.
For example, enter: 10
Output result: 0, 2, 4, 6, 8, 10.
Topic analysis
We first need a loop to find all the numbers up to 10, and then determine if they are even. The topic requires the way of generator, we only need to write a generator function, after finding the qualified number, use yield output. Finally, loop the generator directly, find the desired values and put them in the list, and then separate the output with a comma.
Referenc
Def EvenGenerator (n):
I = 0
While i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.