Python Articles

Page 706 of 855

Using OpenCV in Python to Cartoonize an Image

Arjun Thakur
Arjun Thakur
Updated on 25-Mar-2026 1K+ Views

Image cartoonization is a popular computer vision technique that transforms regular photos into cartoon-style images. While many professional cartoonizer applications exist, most are paid software. Using OpenCV in Python, we can achieve this effect by combining bilateral filtering for color reduction and edge detection for bold outlines. Algorithm Overview The cartoonization process involves five key steps: Apply bilateral filter to reduce the color palette of the image Convert the original image to grayscale Apply median blur to reduce image noise in the grayscale image ...

Read More

OpenCV Python Program to blur an image?

Ankith Reddy
Ankith Reddy
Updated on 25-Mar-2026 699 Views

OpenCV is one of the best Python packages for image processing. Like signals carry noise attached to them, images too contain different types of noise mainly from the source itself (camera sensor). Python's OpenCV package provides ways for image smoothing, also called blurring. One of the most common techniques is using a Gaussian filter for image blurring, which smooths sharp edges while minimizing excessive blur. Syntax cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]]) Parameters src − Input image ksize − Gaussian kernel size as (width, height). Both values must be odd and positive sigmaX ...

Read More

Permutation and Combination in Python?

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 1K+ Views

In this section, we are going to learn how to find permutation and combination of a given sequence using Python programming language. Python's itertools module provides built-in functions to generate permutations and combinations efficiently. A permutation is an arrangement of items where order matters, while a combination is a selection where order doesn't matter. Understanding Permutations vs Combinations Before diving into code, let's understand the difference: Permutation: Order matters. For items [A, B], permutations are (A, B) and (B, A) Combination: Order doesn't matter. For items [A, B], there's only one combination: (A, B) ...

Read More

Python program to Rearrange a string so that all same characters become d distance away

Arjun Thakur
Arjun Thakur
Updated on 25-Mar-2026 1K+ Views

Given a string and an integer d, we need to rearrange the string such that all same characters are at least distance d apart from each other. If it's not possible to rearrange the string, we return an empty string. Problem Understanding The key challenge is to place characters with higher frequencies first, ensuring they have enough positions to maintain the required distance d. Example 1 str_input = "tutorialspoint" d = 3 # Result: "tiotiotalnprsu" # Same characters are at least 3 positions apart Example 2 str_input = "aaabc" d = ...

Read More

Python program to Find the first non-repeating character from a stream of characters?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 9K+ Views

In this article, we will find the first non-repeating character from a stream of characters. A non-repeating character is one that appears exactly once in the string. Let's say the following is our input ? thisisit The following should be our output displaying first non-repeating character ? h Using While Loop We will find the first non-repeating character by comparing each character with others using a while loop. This approach removes all occurrences of each character and checks if only one was removed ? # String my_str = "thisisit" ...

Read More

Python program to Count words in a given string?

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 4K+ Views

Sometimes we need to count the number of words in a given string. Python provides several approaches to accomplish this task, from manual counting using loops to built-in methods like split(). Using For Loop This method counts words by detecting whitespace characters manually − test_string = "Python is a high level language. Python is interpreted language." total = 1 for i in range(len(test_string)): if test_string[i] == ' ' or test_string[i] == '' or test_string[i] == '\t': total = total + 1 print("Total ...

Read More

Increment and Decrement Operators in Python?

Arjun Thakur
Arjun Thakur
Updated on 25-Mar-2026 66K+ Views

Python does not have unary increment/decrement operators (++/--) like C or Java. Instead, Python uses compound assignment operators for incrementing and decrementing values. Basic Increment and Decrement Operations To increment a value, use the += operator ? a = 5 a += 1 # Increment by 1 print(a) 6 To decrement a value, use the -= operator ? a = 5 a -= 1 # Decrement by 1 print(a) 4 Why Python Doesn't Have ++ and -- Operators Python follows the ...

Read More

Print Single and Multiple variable in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 28K+ Views

To display single and multiple variables in Python, use the print() function. For multiple variables, separate them with commas or use formatting methods. Variables are reserved memory locations to store values. When you create a variable, you reserve space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Print Single Variable in Python To display a single variable, pass it directly to the print() function ? Example # Printing single values print(5) print(10) # Printing variables name = ...

Read More

Swap two variables in one line in using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

Python provides several ways to swap two variables in a single line. The most Pythonic approach uses tuple unpacking, but you can also use arithmetic or bitwise operators ? Using Tuple Unpacking (Recommended) Python's tuple unpacking allows you to swap variables in one elegant line using the comma operator ? a = 5 b = 10 print("Before swapping:") print("a =", a) print("b =", b) # Swap two variables in one line using tuple unpacking a, b = b, a print("After swapping:") print("a =", a) print("b =", b) Before swapping: a ...

Read More

When to use yield instead of return in Python?

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 1K+ Views

In Python, yield and return serve different purposes. The return statement terminates function execution and returns a value, while yield pauses execution and creates a generator that can resume from where it left off. Understanding return Statement The return statement stops function execution immediately and optionally returns a value to the caller ? def get_numbers(): print("Starting function") return [1, 2, 3, 4, 5] print("This line never executes") numbers = get_numbers() print(numbers) Starting function [1, 2, 3, 4, 5] ...

Read More
Showing 7051–7060 of 8,549 articles
« Prev 1 704 705 706 707 708 855 Next »
Advertisements