Skip to main content

Defining and Using Python Generators

Hands-On Lab

 

Photo of Keith Thompson

Keith Thompson

DevOps Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

Generators are Python functions that behave like iterators. By using generators we're able to create sequences that are evaluated as each item is needed, making them more memory-efficient compared to simply having lists. In this hands-on lab, we'll be building a generator function that behaves in a way similar to the built-in range function, except it will yield string characters instead of integers. To feel comfortable completing this lab you'll want to know how to do the following: Defining and using generators. Watch "Defining and Using Generators" video from the [Certified Entry-Level Python Programmer Certification][1] course. Working with for loops. Watch "The for Loop" video from the [Certified Entry-Level Python Programmer Certification][1] course. * Using the ord and chr functions. Watch the "String Encodings and Functions" video from the [Certified Entry-Level Python Programmer Certification][1] course. [1]: https://linuxacademy.com/cp/modules/view/id/413

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.