No video

I DIDN'T KNOW You Could Do THIS With "Yield" In Python

  Рет қаралды 26,346

Indently

Indently

Күн бұрын

I didn't know that you could do this with yield in Python. In this video I will be showing you some extra functionality that you can use with the yield keyword when working with generators.
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels5

Пікірлер: 43
@ProfRoxas
@ProfRoxas Жыл бұрын
I remember seeing this when I was learning about the yield keyword, but never actually used it. When you mention you can use multiple statements in a function at 3:32, it makes sense if you think of the yield keyword as a pause where you return a value, but when calling again (with the next) you resume from that statement. You get a StopIteration when the generator reaches the end of that function, which means no more items
@DrDeuteron
@DrDeuteron Жыл бұрын
yield is also an assignment statement: value = yield value coroutines.
@ExDarkx3
@ExDarkx3 Жыл бұрын
Thanks for educating me. I rarely use yield and so this is even more fascinating for me
@DrDeuteron
@DrDeuteron Жыл бұрын
I dislike: def meth() result = [] for.... result.append(something) return result It's clumsy, so I'll do def imeth() for.... yield something def meth(): return list(self.imeth()) I find it easier to debug, and look at.
@gardnmi
@gardnmi Жыл бұрын
I didn't know you couldn't pickle generators :(. Thought I was being clever. I discovered that you can wrap a generator with enumerate however to easily create an offset that you can save to use if you need to pick up where you left off though you still need to iterate to that point from the beginning. I was hoping a pickle would save the state.
@alenasenie6928
@alenasenie6928 Жыл бұрын
Why would you need to iterate? In many generators, specially built-in functions, you can start at a given iteration, enumerate can have a start value and you can split the list or other iterator with values you don't need and only keep the ones you do need
@dcollett
@dcollett Жыл бұрын
Your python videos are the best on the internet. Thanks so much!
@Greenbay-bn3yk
@Greenbay-bn3yk Ай бұрын
I love the way you teach. 😀
@vaha2833
@vaha2833 Жыл бұрын
When one video is Enough.... Good explanation. Thanks.
@sultanahmed9694
@sultanahmed9694 6 ай бұрын
Very simple explanation, thank you
@y2ksw1
@y2ksw1 4 ай бұрын
This is pretty useful for games and for generating preemptively prime numbers and such, in particular because the big work is eventually done in the background (?). I will test that.
@comfixit
@comfixit 7 ай бұрын
Pretty slick. Great explanation
@rondamon4408
@rondamon4408 5 ай бұрын
Sehr gut!!
@HeyZReD
@HeyZReD Жыл бұрын
Great video! I have seen the "yield from" being used somewhere but never dug any deeper into how it works. 👍🏽👍🏽
@user-if1dj7fy2y
@user-if1dj7fy2y 4 ай бұрын
Bravo 🌞 Lit 🌟 Gratitude 🎉 for your satisfactory Work 🚀🌱
@airatvaliullin8420
@airatvaliullin8420 Жыл бұрын
This is not the main purpose of this `yield from ` syntax. See the mcoding video for details
@castlecodersltd
@castlecodersltd Жыл бұрын
Nice, thanks for sharing
@prasangsinghal262
@prasangsinghal262 6 ай бұрын
Nice explantion. And about the IDE, is it PyCharm or Fleet?
@banana1093
@banana1093 4 ай бұрын
It's PyCharm
@nextisnowmain
@nextisnowmain 4 ай бұрын
Very informative
@redpillsatori3020
@redpillsatori3020 Жыл бұрын
Great content. Subbed!
@kvelez
@kvelez 9 ай бұрын
def random_nums(): for i in range(3): yield i def randoms(): for i in range(100, 110): yield i def generator(): yield from random_nums() print("Next") yield from randoms() if __name__ == "__main__": gen = generator() print(next(gen)) print(next(gen)) print(next(gen)) print(next(gen)) print(next(gen)) print(next(gen))
@maciejdudek2381
@maciejdudek2381 4 ай бұрын
what ide you are using? it looks like vscode but the buttons or run and debug are different
@banana1093
@banana1093 4 ай бұрын
It's PyCharm, made by JetBrains
@maximpapusha5032
@maximpapusha5032 Жыл бұрын
Generator comprehantion ist quite useful especially if applying expensive functions 😁
@ricgondo
@ricgondo Жыл бұрын
This is cool!
@rishiraj2548
@rishiraj2548 Жыл бұрын
Thanks a million
@Cpt.C
@Cpt.C Жыл бұрын
Just like using list comprehensions instead of simple for loops, I like how u can just make only one line instead of several
@amirthaanagamuthulilly3970
@amirthaanagamuthulilly3970 Жыл бұрын
Explain the last part clearly please what is the need for next keyword there even without next keyword that generator can yield random numbers function but why it execute random number 100() function as a list what is the use of next here why the first random number function didn't execute after removing next (generator)
@DrDeuteron
@DrDeuteron Жыл бұрын
next just takes 1 item out of the iterator. list takes them all.
@alias77799
@alias77799 4 ай бұрын
Thanks for knowledge
@viethungoan7275
@viethungoan7275 Жыл бұрын
Is your IDE VSCode ? It look different
@itsshamyht
@itsshamyht 10 ай бұрын
pycharm
@allo5668
@allo5668 Жыл бұрын
So does that mean you could yield from range(10)??? 🤯
@link_safe
@link_safe Жыл бұрын
Correct
@sg8581
@sg8581 Жыл бұрын
👍
@jasonbourn29
@jasonbourn29 Жыл бұрын
I had a use of this in streaming live vedio in opencv flask setup
@ballex2534
@ballex2534 Жыл бұрын
what is that IDE?
@mihaiharas8098
@mihaiharas8098 Жыл бұрын
Looks like Visual Studio Code
@mohammedhayyoun
@mohammedhayyoun Жыл бұрын
Pycharm
@betapacket
@betapacket Жыл бұрын
3rd
@joaquinfernandez6066
@joaquinfernandez6066 4 ай бұрын
Pretty basic, honestly I was expecting to learn about the true reason behind why the yield from statement was added to python, not this kind of shortcut usage
@sprayg0d759
@sprayg0d759 4 ай бұрын
No ego only education 🫂
How To SCHEDULE Functions & Tasks In Python (FULL GUIDE)
19:49
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 98 М.
How I Did The SELF BENDING Spoon 😱🥄 #shorts
00:19
Wian
Рет қаралды 37 МЛН
Kids' Guide to Fire Safety: Essential Lessons #shorts
00:34
Fabiosa Animated
Рет қаралды 17 МЛН
PEDRO PEDRO INSIDEOUT
00:10
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 19 МЛН
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 58 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 802 М.
5 More Useful F-String Tricks In Python
9:38
Indently
Рет қаралды 47 М.
5 Amazing Ways to Automate Your Life using Python
18:40
Internet Made Coder
Рет қаралды 244 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 66 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
5 Good Python Habits
17:35
Indently
Рет қаралды 508 М.
Python Generators
15:32
mCoding
Рет қаралды 135 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 398 М.