Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

810 articles

Short Circuiting Techniques in Python?

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

Short-circuiting is an optimization technique where Python stops evaluating boolean expressions as soon as the result is determined. This behavior can be confusing for beginners but is essential for writing efficient code. Understanding the Confusion New programmers often misunderstand how and and or operators work. Let's examine these expressions ? print('x' == ('x' or 'y')) print('y' == ('x' or 'y')) print('x' == ('x' and 'y')) print('y' == ('x' and 'y')) True False False True How OR Short-Circuiting Works With or, Python evaluates the first value. If it's truthy, Python returns ...

Read More

Mouse and keyboard automation using Python?

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

Python automation of mouse and keyboard controls allows you to create scripts that can perform repetitive tasks, control applications, and simulate user interactions. The PyAutoGUI module provides a simple way to automate GUI interactions programmatically. Installing PyAutoGUI PyAutoGUI is a cross-platform GUI automation library that needs to be installed separately ? pip install pyautogui Mouse Automation PyAutoGUI provides several functions to control mouse movement and clicking. Let's explore the basic mouse operations ? Getting Screen Information import pyautogui # Get screen dimensions screen_size = pyautogui.size() print(f"Screen size: {screen_size}") ...

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 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

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

Whatsapp using Python?

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 816 Views

WhatsApp automation using Python allows developers to send messages programmatically. Since WhatsApp doesn't provide official API access for personal accounts, we use Selenium to automate WhatsApp Web through a browser interface. Requirements To create a WhatsApp automation script, you need three essential components ? Install Selenium Install Selenium using pip ? pip install selenium Chrome WebDriver Download the Chrome WebDriver compatible with your Chrome browser version from the official ChromeDriver website. Extract it to a known location on your system. WhatsApp Account Ensure you have an active WhatsApp account ...

Read More

Changing Class Members in Python?

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 662 Views

Python object-oriented programming allows variables to be used at the class level or the instance level. Class variables are shared among all instances of a class, while instance variables are unique to each object. Understanding the difference between class and instance variables is crucial when modifying class members. Let's explore how to properly change class variables through examples. Class vs Instance Variables Here's a basic example demonstrating class and instance variables ? # Class Shark class Shark: animal_type = 'fish' # Class Variable ...

Read More

Inplace vs Standard Operators in Python

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 575 Views

Python provides two types of operators: inplace operators that modify variables directly, and standard operators that create new values. Understanding the difference helps you write more efficient code. Inplace Operators Inplace operators modify the original variable without creating a copy. They use compound assignment syntax like +=, -=, etc. Basic Example a = 9 a += 2 print(a) 11 The += operator adds 2 to the original value of a and updates it in place. Common Inplace Operators += (addition) -= (subtraction) *= (multiplication) /= (division) %= ...

Read More

Time Functions in Python?

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

Python provides a comprehensive library to read, represent and manipulate time information through the time module. Date, time and datetime are objects in Python, so whenever we perform operations on them, we work with objects rather than strings or timestamps. The time module follows the EPOCH convention, which refers to the starting point for time calculations. In Unix systems, EPOCH time started from January 1, 1970, 12:00 AM UTC. Understanding EPOCH Time To determine the EPOCH time value on your system ? import time print(time.gmtime(0)) time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, ...

Read More

Locating and executing Python modules (runpy)

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

The runpy module allows you to locate and execute Python modules using the module namespace rather than the filesystem. This is the same mechanism that supports Python's -m command line option. Understanding runpy Module The runpy module defines two main functions for executing modules dynamically: run_module() − Executes a module by name run_path() − Executes a module by file path run_module() Function This function executes the code of the specified module and returns the resulting module globals dictionary. Syntax runpy.run_module(mod_name, init_globals=None, run_name=None, alter_sys=False) Parameters mod_name − ...

Read More
Showing 1–10 of 810 articles
« Prev 1 2 3 4 5 81 Next »
Advertisements