Vijaykrishna Ram

Find String Length in Python

We can find string length in Python using the built-in len() function. Let’s look at how this function works, and also let’s try finding the length of various types of Python strings using len(). Using len() Let’s look at some simple examples to illustrate len(). This prints 20 because it is the number of characters

Find String Length in Python Read More »

Python String find()

The Python string find() method is used to check if a string is a substring of another string. Often, when we want to check if a string contains another string, find() is very useful to solve this problem. Let us understand how we can use this, through some simple examples. Syntax of Python String Find()

Python String find() Read More »

Python – Print to File

In this article, we shall look at some of the ways to use Python to print to file. Method 1: Print To File Using Write() We can directly write to the file using the built-in function write() that we learned in our file handling tutorial. Output (Assume that output.txt is a newly created file) Method

Python – Print to File Read More »

Python struct Module

The Python struct module is used to provide a simple Pythonic interface to access and manipulate C’s structure datatype. This can be a handy tool if you ever need to deal with C code and don’t have the time to write tools in C since it is a low-level language. This module can convert Python

Python struct Module Read More »

Python chr() and ord()

Python’s built-in function chr() is used for converting an Integer to a Character, while the function ord() is used to do the reverse, i.e, convert a Character to an Integer. Let’s take a quick look at both these functions and understand how they can be used. The chr() function Syntax This takes in an integer

Python chr() and ord() Read More »

Python bytes()

Python bytes() is a built-in function which returns a bytes object that is an immutable sequence of integers in the range 0 <= x < 256. Depending on the type of object passed as the source, it initializes the byte object accordingly. Let’s look at how we can use this function in this article. Syntax

Python bytes() Read More »

Python String translate()

Python’s in-built method for the String class, str.translate(), is used to map a string with a translation table. The translate() method simply converts it using the translation table rules. Let’s understand more about the method in this article. Syntax of Python String translate() Since the translate() function returns a new string with each character in

Python String translate() Read More »