Home » Python

Tag Archives: Python

Python String replace Method

Hello in this tutorial, we will understand the string replace() method in python programming. 1. Introduction replace() method in python programming returns a copy of a string where all occurrences of a substring are replaced by the new string. The method also accepts an optional count argument only if the first count occurrences are to be replaced. 1 my_string.replace(old_string, new_string, ...

Read More »

Python os.walk() Method

Hello in this tutorial, we will understand the os.walk method to list the files in a directory using the python programming. 1. Introduction The os.walk(……) method will generate the file names in a directory tree by walking the tree either top-down or bottom-up. Represented with the following syntax – 1 os.walk(path_name, topdown=False, onerror=None, followlinks=False) Where, path_name denotes the directory path ...

Read More »

Constructor Example in Python

Hello in this tutorial, we will explain how a Constructor works in python programming, using examples. 1. Introduction Constructors are used for instantiating an object and assign values to the data members of a class. In python, the method __inti()__ simulates the class constructor and is called every time the class is instantiated. It accepts the self keyword as an ...

Read More »

Python map function Example

Hello in this tutorial, we will understand the different ways to use the map function in python programming. 1. Introduction The map() function in python programming executes a given function for each item in an iterable. The entity to the function is sent as a parameter. Following the syntax for the map() function – 1 2 3 4 map(function, iterables) ...

Read More »

Python Remove Character from String Example

Hello in this tutorial, we will explain the different ways to remove the occurrences of a character from a string in the python programming language. 1. Introduction To remove the occurrences of a character from a string in the python programming language we will use the two commonly used replace and translate methods. Using the string replace() method we can ...

Read More »

Check if a key is in dictionary Python Example

Hello in this tutorial, we will understand the different ways to check if a key is in a dictionary data structure in the python programming language. 1. Introduction A dict is a valuable data structure in the python programming and it holds the key-value pair. To find the existing of a key in the dict data structure we will explore ...

Read More »

Python zip() function Example

Hello in this tutorial, we will explain the zip() function in the python programming language. 1. Introduction The zip() function in python takes multiple iterables and aggregates them into a python tuple (i.e. collection of objects) and returns it. The syntax of zip() function in python programming is – Syntax 1 2 # iterables are the built-in iterables (like list, ...

Read More »

Python main function Example

Hello, in this tutorial, we will learn about the main function in the Python programming language. 1. Introduction The main function in python programming is the starting point of a program. The python interpreter runs the code sequentially. The main function in python programming gives the program a starting point for the execution and is useful to better understand how ...

Read More »

Sets in Python

Hello, in this tutorial, we will explain Sets in Python programming language. 1. Introduction The Set data structure in python programming is: A data structure that cannot contain the duplicates elements A data structure which is unordered and un-indexed Elements are immutable but the whole Set is mutable There is no index attached to any element in a Set 1.1 ...

Read More »