Programming Articles - Page 400 of 3363

Python Program to get the index of the substring in a string

Rohan Singh
Updated on 17-Apr-2023 10:54:19

2K+ Views

In Python we can use the find() and index() methods to get the index of the first occurrence of the substring in a string. Python provides various string manipulation functions to modify and access text data. In this article, we will write a program to get the index of the substring in a string. Method 1: Using the find() method The find method searches for the specific substring which is passed as a parameter to the function and returns the starting index of the substring. If the substring is not found in the string then the find() method returns -1. ... Read More

Python program to get characters from the string using the index

Rohan Singh
Updated on 17-Apr-2023 10:50:38

863 Views

In Python, we can use various methods like using square brackets, slicing, and using indices to get characters from the string with the help of their index. A string is a sequence of characters with each character being assigned a unique index. The index specifies the position of the character in the string. The index of the first character starts with 0 and the index of the last character in the string is the length of the string minus one. We can use the index value of the character to access a particular character in the string. Accessing Characters From ... Read More

Python Program to Get a Character From the Given String

Rohan Singh
Updated on 17-Apr-2023 10:49:08

462 Views

In Python we can get a character from the given string using the indexing operator ‘[ ]’, using slices, and using indices separated by a colon. By passing the index of the character we want to access to the index operator we can easily get the character from the string. In this article, we will see how we can access the character of the string using the index operator. Using [ ] Operator Syntax string[index] Here string is the given string from which we want to access a specific character. The index is the index of the character in ... Read More

Python Program To Find all the Subsets of a String

Rohan Singh
Updated on 17-Apr-2023 10:46:28

2K+ Views

In Python, a subset of a string is a sequence of characters that is part of the original string. We can find all the subsets of a string using itertools module in Python. In this article, we will see how we can generate all the subsets of a string by making all possible combinations of characters in the string. Syntax itertools.combination(string, r) The combination() function of itertools module takes the string and r which represents the size of different combinations of strings that are possible.It returns all the combinations of characters of the string that are possible. Algorithm ... Read More

Python Program to divide a string in 'N' equal parts

Rohan Singh
Updated on 17-Apr-2023 10:44:40

5K+ Views

In Python, a string can be divided into N equal parts using the slicing method. Substrings of equal length can be extracted using the Python slicing method by specifying the starting and ending index of the substring. In his article, we will see how we can divide a string into N equal parts using the Python slicing method. To divide a string into N equal parts we need to create a function that takes the original string and the number of parts in which the string is to be divided as input and returns the resultant N equal strings.If the ... Read More

Python Program to Display all the directories in a directory

Rohan Singh
Updated on 17-Apr-2023 10:41:28

492 Views

In Python, we can use the pathlib module, os module, and glob module to display all the folders in a directory. The os module contains various functions like os.scandir, os.walk , os.listdir or glob(), and iglob() methods, etc to list all the directories in a directory. A directory is a folder in a file system that stores various files or more folders. Method 1: Using the Pathlib Module We can use the Path.iterdir() function to get the path object of the contents in the directory. We can then iterate over the path objects and filter out the directories using the path.is_dir() ... Read More

Why JavaScript is Used in Blockchain?

Kalyan Mishra
Updated on 14-Jul-2023 16:59:58

352 Views

In this article, you will learn about the use of JavaScript in blockchain technology. We will get to know the reason for using JavaScript in the blockchain Furthermore we will also know about twins' language. JavaScript is a dynamically typed language which perform type checking of language at runtime. JavaScript may not be perfectly accurate but still it is widely used in the blockchain development due to its versatility, popularity, and ease of use. One reason why JavaScript is used in blockchain and makes it a twin language is its ability to run on both the client-side and server-side, which ... Read More

Solving the First Law of Thermodynamics using Python

Dr Pankaj Dumka
Updated on 14-Apr-2023 13:44:43

2K+ Views

The first law of thermodynamics is related to energy conservation, i.e., if energy in form disappears then the energy will in appear in some other form. In thermodynamics majorly we are concerned about heat, work and internal energy. Heat and work are the form of energy which are also called as "energy in transit", hence they are path functions. They cannot be stored by a system, whereas internal energy is the property of the system which can be stored by system. For a closed system, the first law is written as − $$\mathrm{\Sigma Q=\Sigma W}$$ But this is only valid ... Read More

Python Program to Differentiate String == operator and__eq__() method

Rohan Singh
Updated on 17-Apr-2023 10:30:38

358 Views

In Python, the comparison operator (==) and equals() methods are used in different ways when working with strings. To differentiate between the == operator and the equals method in Python we have to use them with string comparison. String comparison widely occurs when we work with strings in data analysis and machine learning. In this article, we will see how we can differentiate between the == operator and the equals() method when used with strings. == operator in Python The == is a comparison operator used to compare two string values. It returns True when the value of the string ... Read More

Python Program to demonstrate the string interpolation

Rohan Singh
Updated on 17-Apr-2023 10:29:01

289 Views

In Python, we can demonstrate string interpolation using the f-string, %operator, and format() method. String Interpolation is the process of inserting dynamic data or variables in the string. It is useful when a string is formed using variables or expressions without using any string formatting or string concatenation. In this article, we will see how we can use Python to do string interpolation. Method 1 : Using f-string An f-string is a string literal which starts with f or F. The prefix f or F indicates that the string is an f-string. The string contains the expression which is enclosed ... Read More

Advertisements