Python check length and size of string.

In this python article, We are going to learn python built-in functions len() and getsizeof(). len(): Using len() function we can check the length of an object(count number of items). In short len() function returns us the number of elements present in the sequence (List, Tuple, String, range) or in a mapping (Dictionary or set). getsizeof(): Using getsizeof() function we can check how much memory in bytes is allocated to store a complete object. Introduction to len() function: Basically len() function queries the container and returns

Read More

Python string count() method.

In this article we are going to learn python string count() method which is associated with python string data type. Python string count method is used to count the number of occurrences of sub-string in a string. Basically it counts the number of overlapping occurrences of a sub-string. It searches the sub-string in a given string and returns how many times the sub-string is repeated. String count method in python is useful to find out how many times a specific character or a word or a

Read More

Using python read file line by line and create a list.

In this article we are going to see, How we can read a file line by line using python and create a python list with each line as a list element. There are many ways to do this task and in this article we are going to cover few of them. Suppose you are having a text file named “Text.txt” with following content. Line 1. Line 2. Line 3. Solution 1: Using for loop and append method. New_list = [] with open(“Text.txt”, “r”) as file: for

Read More

Python list comprehension along with examples

In this article, We are going to learn how list comprehension works along with its examples. So basically Python List comprehension is a simple and elegant way of creating a list in python. It returns us a new list after performing specified operation on each element of iterable (List or sequence). List comprehension requires a input list and operation statement. During the execution of program it takes each element of input list and will perform specified operation on that element. Output after performing operation will be

Read More

Python package

In this article we are going to learn about what is python package. How to create a package in python. How to import a module from package also rename while importing. What is significance of file “__init__.py” in package and how package initialization works. What is Package in Python: Python package is a directory with modules in it. Basically when our python code gets bigger then it becomes very difficult to maintain it and the only preventive solution is to keep the code well organized. Write

Read More

Python Modules

In this article we are going to learn about python modules. How to a write a python module. Different ways of importing a python module into a program. Most commonly used built-in python modules and how search path works. What is python module? Python module is a python file containing python definitions and executable statements. Biggest advantage of python module is we can use any python program readily into our program without actual copying the code definitions. When a program gets bigger then it becomes very

Read More

Python String Split method

In this article we are going learn about how python split method is used to split the string and produce a list. What is the syntax of python split. Sometimes we may want to break the long string and convert it into a small segments of strings. Python split is an action opposite to the string concatenation i.e in string concatenation we join multiple strings into one. Whereas using python split we can break the string into required segments. This purpose can be served using built-in

Read More

Python Dictionary data type

In this python article, We are going to learn next python Dictionary data type. What is dictionary data type, How to create it. How to add/edit/delete and access dictionary element. Different methods associated with python dictionary data type. So let’s get started with the python dictionary data type tutorial. What is python dictionary data type: Dictionary data type in Python is an unordered collection of data values. In simple words it is a collection of key:value pairs. Each key is mapped to its associated value. So the

Read More

Python Directory management

In this article, We are going to learn about files and directory management in python. Different methods available in python os path module. We are going to cover topics like, How to create a folder using python, How to rename a directory using python, Listing all directories and working with them. What is directory/folder management in python: Basically Directory or folder is a container for holding the files and sub-directories. In context of python directory/folder and file management we are going to perform following operations on

Read More

Python File Handling I/O – Reading and Writing files in python

In this article we are going to learn about file handling in python. How to open a file using python, Different python methods to Read and write a content in a file. Close the file once we are done with the editing. Also we are going to see other methods available in python read/write mode. File handling in python: So before getting started with the topic file handling in python. Let’s first try to understand what is a file? Term “file” is very basic concept for

Read More