Category: Python Primer

  • What is enumerate in Python

    The enumerate in Python is a built-in function. It takes an iterable object. And returns an iterator that produces tuples. The iterable object could be a list, tuple, or string. Moreover, it contains the index and the value of each element of the object. Here’s an example. Here we can use enumerate to iterate over…

  • What is for loop in Python give example?

    The for loop in Python is one of the main looping constructs. Usually we use the for loop when we want to iterate over the sequence.  This sequence could be a collection, such as tuple, list, or even a string. As a result of iteration, the placeholder variable takes every item as we iterate over…

  • Python while loop

    In our previous section we have seen examples of if-else. In this section, we will take a look at Python while loop. The common question that comes to our mind is which one is faster? For or while loop?  In the Java section, we have tried to find out the answer. You may have a…

  • if else in python

    The if else in Python is a part of flow control. In this section we will try to understand how the if-else block works in Python. If you are new to Python, you may visit the other beginner friendly articles in the Python Primer category. Flow control plays an important role not only in Python…

  • Namespace and scope in Python

    Namespace and scope in Python are very much interrelated. In this section, we will take a look at this very important concept. Before giving an example we can take a look at the file systems in a computer. Suppose in C drive, we try to save a file under the same name. Will it allow…

  • Operators Python: Comparison, Logical and Identity

    In the last section we have seen arithmetic operators in Python. However we didn’t discuss Arithmetic Operators Python precedence. Therefore that should be the first task that we should address. First of all, what is arithmetic precedence? When we have many operations at our hands, such as the following example. What will be the value…

  • What are operators in Python

    Why do we use operators in Python? For one reason of course. To perform various kinds of operations on variables. Arithmetic operations like addition, subtraction, multiplication or division are nothing new to us. Right?  As a result, we know how to use those operators. However, a programming language needs a lot more than that.  If…

  • How do you show Python output

    We can show Python output in many ways. In other words, there are many ways that we can adopt to show the output in Python. In this section, we will see all the alleys and backstreets to display the output. Firstly, let us clear a basic point in mathematics and programming.  A function primarily handles…

  • How Python Dictionary functions work

    In our previous section, we have seen a few examples of Python dictionary functions. In this section we will discuss more. Let’s start with the popitem() method. This method removes and returns the last key, value pair inserted into the Python Dictionary. However, the popitem() doesn’t take any arguments. Let’s take a look at one…

  • What are Python dictionary functions

    We have learned how a Python dictionary works. However, we use Python dictionary functions without knowing that they are built-in methods. In the previous sections we have seen how the  Python Set and Dictionary belong to the collections or data structures. We have also discussed lists and tuples. However, lists and tuples differ in nature.…

  • Dictionary functions in Python

    Dictionary functions are a few built-in methods in Python. Using these functions we can do many operations on a dictionary. However, in the previous section we have seen how a python dictionary behaves as a mutable data structure. But promised to show the delete method in the later section. Therefore, before discussing the dictionary functions…

  • Dictionary is mutable in python

    A Dictionary is mutable in Python. What does that mean? In short, it means we can use the concept of CRUD with a dictionary. Let’s clarify the concept a little bit. Actually it’s simple. CRUD represents four words – C for Create, R for retrieve, U for update, and D for delete. In the coming…

  • Python Set and Dictionary

    Python Set and Dictionary belong to the collections or data structures. We have discussed lists and tuples before. With reference to the previous discussion we have also seen how lists and tuples differ in nature. The Python Set and Dictionary are also different.  Firstly, Set is an unordered collection of unique items.  Remember, unique items.…

  • Python collections comparison

    In our previous discussion, we have seen one of the most important collections List. Now we can go through python collections comparison. We’ve also seen how we can change the value of a list and change the Python collection. However, in some cases, we need to keep the value write-protected.  In short, we don’t want…

  • What is the need of Python collections?

    Without the Python collections we cannot handle the big data. In short, the data structure or collections in python is super important. There are four types of Python collections. In this section we will try to understand List. One of the most used data types in collections is the List. We have discussed data types…

  • What are data types in Python?

    We have already seen data types in Python. But in this section we will dig deep and learn the topic in depth. Now in many programming languages, we explicitly mention the data type. We call them Strongly typed, or Statically typed languages. On the other hand, in Python it is not mandatory at all. We can…

  • What are literals in Python?

    In our previous discussion we have seen how we can assign value to a variable. We refer to that value as literals in Python. In other words, literals refer to raw data. As a result, there are different types of literals in Python.  Let’s start with numeric literals which are nothing but a decimal literal,…

  • What are variables in Python

    Consider variables in Python as containers that contain some data. It could be integer, string or boolean. At the same time, whenever a Python interpreter sees a variable it considers it as a named-location. In reality a variable stores data in the memory.  However, at the same time it tells the interpreter that this is…

  • What is Python Docstring?

    First of all let’s put one important concept in order. What is Python docstring? Is it the same as Python comments? The answer is no. We have discussed the role of Python comments before. Sometimes beginners may find them the same.  Because for multi-line Python comments we use three single quotes – (‘’’ comments can…

  • Statement and Indentation in Python

    Statement and indentation in Python are important concepts that a beginner should know at the very beginning. In this section, we will see how it works.  If you are new to Python, please visit the previous sections, where we have discussed keywords and identifiers. Besides that, we have also discussed how to start learning Python.…

  • What are keywords and identifiers in Python?

    Keywords and identifiers in Python separately refer to two different types of concepts. Therefore, don’t get confused. What are keywords in Python? Firstly, they are reserved words that we use for special purposes.  We’ll see in a minute what they are and how they work. Secondly, we cannot use keywords as names given to any…