Skip to main content

Posts

Showing posts from March, 2025

Python Generator

 Generators are useful when we want to produce a large sequence of values but we don't want to store them in memory at once yield keyword helps python to execute generator .  Key Features of Generators Memory Efficient – They do not store all values in memory; instead, they generate values one by one. Lazy Evaluation – Values are produced only when needed. Automatic State Retention – The function retains its state between yield calls. Iterable – Generators can be iterated using a for loop or the next() function.

4 built-in data types in Python

 There are 4 built-in data types available in python.  Lets learn about them  List:  Lists are used to store multiple items in a single variable. List items are ordered, changeable, and allow duplicate values. List items are indexed, the first item has index [0], the second item has index [1] etc. Python Tuples: Tuples are used to store multiple items in a single variable. A tuple is a collection which is ordered and unchangeable.  Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created.  Since tuples are indexed, they can have items with the same value: thistuple = ( "apple" ,  "banana" ,  "cherry" ,  "apple" ,  "cherry" ) print (thistuple) Python Sets: A set is a collection which is unordered, unchangeable*, and unindexed. Set items are unordered, unchangeable, and do not allow duplicate values. thisset = { "apple" ,  "banana" ,  "cherry" } print (thiss...