Found 10476 Articles for Python

Automated software testing with Python

Hafeezul Kareem
Updated on 01-Nov-2019 07:51:47

686 Views

In this tutorial, we are going to learn about automating testing in Python. After writing code, we have to test them by giving different types of input and check whether the code is working correctly or not.We can do it manually or automatically. Doing manual testing is very hard. So, we are going to learn about automated testing in Python. Let's start.We have a module called unittest, which is used to test the code automatically. We are going to work with this module in this tutorial. It's straightforward for a beginner to get started with the unittest module for testing. ... Read More

Amazing hacks of Python

sudhir sharma
Updated on 14-Jul-2025 15:42:30

216 Views

Python is one of the programming languages known for its simple syntax, readability. Whether working on development, data analysis, or automation, Python provides the tools to get the task done with less effort. But beyond the basics, Python has some hacks that make the code not only shorter but also more efficient. These are not bugs or workarounds, but the smart ways of using the Python built-in features and functions to solve tasks in a faster manner. In this article, we are going to learn about the amazing hacks of Python. Performing a Swap Without a ... Read More

Find all the patterns of “1(0+)1” in a given string using Python Regex

Pradeep Elance
Updated on 23-Oct-2019 08:22:30

253 Views

In this tutorial, we are going to write a program which finds all the occurrences of the 1(0+1) in a string using the regexes. We have a re module in Python which helps us to work with the regular expressions.Let's see one sample case.Input: string = "Sample 1(0+)1 string with 1(0+)1 unnecessary patterns 1(0+)1" Output: Total number of pattern maches are 3 ['1(0+)1', '1(0+)1', '1(0+)1']Follow the below steps to write the code for the program.Algorithm1. Import the re module. 2. Initialise a string. 3. Create a regex object using regular expression which matches the pattern using the re.compile(). Remember to ... Read More

Check if both halves of the string have the same set of characters in Python

Pradeep Elance
Updated on 23-Oct-2019 08:20:20

165 Views

We have to check whether two halves of a string have the same set of characters or not in Python. The frequency of the characters in the two halves must be identical. If the length of the string is odd, ignore the middle and check for the remaining characters. Follow the below steps to write code for the program.Algorithm1. Initialize a string. 2. Initialize an empty dictionary variable alphabets. 3. Initialize a variable mid with length / 2. 4. Write a loop until mid element.    4.1. Initialize the corresponding dictionary item by alphabets[char] with one if it's not initialized. ... Read More

Basic calculator program using Python program

Niharikaa Aitam
Updated on 20-Jun-2025 19:27:44

1K+ Views

In this tutorial, we are going to build a basic calculator in Python. As we all know that a calculator will give six options to the user from which they select one option and we will perform the respective operation. Following are the arithmetic operations that we can perform using a basic calculator - Addition Subtraction Multiplication Division Floor Division Modulo Steps in Developing the Basic Calculator Following are the steps involved in creating a basic calculator in Python - Defining Arithmetic Functions First, we are defining all the arithmetic operations that can be performed by using a ... Read More

Calculate n + nn + nnn + … + n(m times) in Python program

Pradeep Elance
Updated on 23-Oct-2019 08:08:59

2K+ Views

We are going to write a program that calculates the following series in Python. Examine the example inputs and outputs for the program that we are going to write.Input: 34 3 + 33 + 333 + 3333 Output: 3702Input: 5 5 5 + 55 + 555 + 5555 + 55555 Output: 61725So, we will have two numbers, and we have to calculate the sum of the series generated as above. Follow the below steps to achieve the output.Algorithm1. Initialize the number let's say n and m. 2. Initialize a variable with the value n let's say change. 3. Intialize a ... Read More

FuzzyWuzzy Python library

Pradeep Elance
Updated on 23-Oct-2019 08:01:52

727 Views

In this tutorial, we are going to learn about the FuzzyWuzzy Python library. FuzzyBuzzy library is developed to compare to strings. We have other modules like regex, difflib to compare strings. But, FuzzyBuzzy is unique in its way. The methods from this library returns score out of 100 of how much the strings matched instead of true, false or string.To work with the FuzzyWuzzy library, we have to install the fuzzywuzzy and python- Levenshtein. Run the following commands to install them.pip install fuzzywuzzyIf you run the above command, you will the following success message.Collecting fuzzywuzzy Downloading https://files.pythonhosted.org/packages/d8/f1/5a267addb30ab7eaa1beab2 b9323073815da4551076554ecc890a3595ec9/fuzzywuzzy-0.17.0-py2.py3-none-any.whl Installing collected ... Read More

Print anagrams together in Python using List and Dictionary

Pradeep Elance
Updated on 23-Oct-2019 07:52:49

692 Views

In this tutorial, we are going to write a program which finds and prints anagrams using list and dictionary. We have different approaches to every problem. Try to write code without following the tutorial. If you are not able to generate any ideas to write logic, follow the below steps.Algorithm1. Initialize a list of strings. 2. Initialize an empty dictionary. 3. Iterate through the list of strings.    3.1. Sort the string and check if it is present in the dictionary as key or not.       3.1.1. If the sorted string is already present dictionary as a key ... Read More

Print first m multiples of n without using any loop in Python

Pradeep Elance
Updated on 23-Oct-2019 07:48:16

727 Views

In this tutorial, we are going to write a program to find out m multiples of a number n without using loops. For example, we have a number n = 4 and m = 3, the output should be 4, 8, 12. Three multiples of four. Here, the main constraint is not to use loops.We can use the range() function to get the desired output without loops. What is the work of the range() function? range() function returns a range object which we can convert into an iterator.Let's see the syntax of range().Syntaxrange(start, end, step)Algorithmstart - starting number to the ... Read More

Python program to count occurrences of a word in a string

Pradeep Elance
Updated on 23-Oct-2019 07:36:17

4K+ Views

In this tutorial, we are going to write a program that counts the number of times a word occurs in the string. You are given the word and a string, we have to calculate the frequency of the word in the string.Suppose we have a string I am a programmer. I am a student. And the word is. The program that we are going to write will return a number 2 as the word occurs two times in the string.Let's follow the below steps to achieve our goal.Algorithm1. Initialize the string and the word as two variables. 2. Split the string ... Read More

Advertisements