Iteration in Python PYTHON by Ravinder Nath Rajotiya - April 19, 2022April 22, 20220 Iteration- for and while loop: Iterations are used for repetitive execution of the same block of code over and over. Loop or iteration are popular block of code in all the programming language like basic, PASCAL, C, JAVA, PHP and all others. They can be numeric or collection based. Type of Iteration There are two types of iteration: a) Definite iteration, in which the number of repetitions is specified explicitly in advance. This is implemented using the for loop. b) Indefinite iteration, in which the code block executes until some condition is met. This type of iteration is implemented using the while loop How to check if an object is iterable? we can check whether an object is itrable r not by passing it to the
Dictionary in Python PYTHON by Ravinder Nath Rajotiya - March 28, 2022March 29, 20220 DICTIONRY IN PYTHON Dictionary is a composite data type. It is used to represent records. The items in dictionary are represented by the key: value pairs. Declaration : A dictionary is declared by enclosing a comma-separated list of key-value pairs in curly braces. The value of an item is always accessed by using its key, therefore the key must be a unique name. Example dict={<key1> : <value>, <key2> : <value>, <key3> : <value>.......<keyn> : <value>} Th following define a dictionay that maps the capital to its country. capital_country = {‘Delhi’ : ‘India’, ‘Karachi’, ‘Pakistan’, ‘Kathmandu’ : ‘Nepal’ } Dictionary in python is similar to List in python. Let us see the similarty and differences between list and dictionary LIST DICTIONARY Is mutable Is mutable Can grow and shrink Can grow and