Python Articles

Page 175 of 852

Ways to increment a character in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 12K+ Views

In this tutorial, we are going to see different methods to increment a character in Python.TypecastingLet's first see what happens if we add an int to char without typecasting.Example## str initialization char = "t" ## try to add 1 to char char += 1 ## gets an errorIf you execute above program, it produces the following result −TypeError          Traceback (most recent call last) in ()       3     4 ## try to add 1 to char ----> 5 char += 1 ## gets an error TypeError: must be str, not intTo increment ...

Read More

Custom len() Function In Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 845 Views

Let's see how can we implement custom len() function in Python. Try it by yourself first using the following steps.StepsGet the iterator from the user string/list/tuple.Define a function with a custom name as you like and invoke it by passing the iterator.Initialize the count to 0.Run a loop until it reaches the end.Increment the count by 1Return the count.Example## function to calculate lenght of the iterator def length(iterator):    ## initializing the count to 0    count = 0    ## iterating through the iterator    for item in iterator:       ## incrementing count       count ...

Read More

Using List as Stack and Queues in Python

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 7K+ Views

In this article, we will learn about Stack & Queue structures in Python 3.x. Or earlier. Here we will discuss the working and modification within these data structures −This includes −Insertion operation (Push, Enqueue)Deletion operation (Pop, Dequeue)Display / Traversing OperationPrerequisites: List & List OperationsRelated Data Structure: List ManipulationRelated ImagesStackIn stacks, objects are stored one over another, and these objects get removed in the reverse order of the arrival i.e. LIFO concept is followed. LIFO means Last in First Out type arrangement is followed in the Stack data structure.Operations on a Stack −Addition / Appending of Element: This increases the stack ...

Read More

Using Iterations in Python Effectively

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 285 Views

In this article, we will learn about how to implement iterators and their effective implementation in Python 3.x. Or earlier. Let’ s take a look at various methods available in python which implements iterators.Type 1 − Implementation Of While Loop With Known LengthExample Codegenre = ("Python", "C", "C++", "Java") print("The topic available on Tutorial's Point are:") i = 0 while (i < len(genre)): print (genre[i]) i += 1ExplanationDue to its less compact structure, this method is not favored. Error Handling is also difficult in this case . Large-scale programs or designs doesn’t use this ...

Read More

Secure Hashes and Message Digest in Python

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 2K+ Views

For the secure hash and message digest process, we should use the hashlib module. This module implements a common interface for different secure hash algorithm like SHA1, SHA224, SHA256, SHA512 etc. Also the RSA’s MD5 algorithm. Older algorithms are known as the Message Digest and the new methods are called Secure Hash. To use this module, we need to import the hashlib module in the python code. import hashlib In this method, there are some predefined algorithms like md5, sha1, sha224, sha256, sha512 are present. We can add additional algorithms from the OpenSSL library. Some methods, constants of ...

Read More

Python Container Datatypes

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 2K+ Views

In the collections there are some container datatypes, which are alternatives to python’s general purpose built-in containers like dict, list, set etc.Some of the containers are −Sr.No.Container & Description1namedtuple()Used to create tuple subclass with the name field2dequeQueue using list type data3CounterSubclass of dict to count the hash-table objects4ChainMapUsed to create single view of multiple mappings5OrderedDictSubclass of dict, where data are added in ordered manner6UserListWrapper for list to easier access.To use this module, we should import it using −import collectionsDeque ObjectThe Deque is basically a generalization of stack and queue structure, where it is initialized from left to right. It uses ...

Read More

The fcntl and ioctl System Calls in Python

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 3K+ Views

To control the files and the io, we should use the fcntl module. It is basically one interface to the fcntl() and ioctl() Unix routines. All methods in this module takes one integer or io.IOBase file-descriptor as their first argument. To use this module, we should import it using. import fcntl There are some modules of the fcntl module, these are − Method fcntl.fcntl(fd, op[, arg]) This method is used to perform the operation on the file using file descriptor. The operation is defined by op. The third argument is optional. It can be either integer type value ...

Read More

Python Interface to Shell Pipelines

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 425 Views

To use the UNIX command pipeline mechanism using python. In the command pipelining a sequence converts from one file to another file. This module uses /bin/sh command line. So we need os.system() and os.popen() methods. To use this module, we should import it using − import pipes The pipes holds Template class − class pipes.Template This class is basically an abstraction of a pipeline. It has different methods. These are as follows. Method Template.reset() This method is used to restore the pipeline template to its initial position. Method Template.clone() This method is used to create another new, ...

Read More

Merge two sorted arrays in Python using heapq?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 598 Views

In this section we will see how two sorted lists can be merged using the heapq module in Python. As an example, if list1 = [10, 20, 30, 40] and list2 = [100, 200, 300, 400, 500], then after merging it will return list3 = [10, 20, 30, 40, 100, 200, 300, 400, 500]To perform this task, we will use the heapq module. This module comes with Python as Standard Library Module. So we need to import it before using it.import heapqThe heapq module has some properties. These are like below −Method heapq.heapify(iterable)It is used to convert an iterable dataset ...

Read More

Dunder or magic methods in python

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 765 Views

magic methods that allow us to do some pretty neat tricks in object oriented programming. These methods are identified by a two underscores (__) used as prefix and suffix. As example, function as interceptors that are automatically called when certain conditions are met. In python __repr__ is a built-in function used to compute the "official" string representation of an object, while __str__ is a built-in function that computes the "informal" string representations of an object. Example Code class String: # magic method to initiate object def __init__(self, string): ...

Read More
Showing 1741–1750 of 8,519 articles
« Prev 1 173 174 175 176 177 852 Next »
Advertisements