Python Articles

Page 679 of 855

OOP Terminology in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 3K+ Views

Object-Oriented Programming (OOP) in Python uses specific terminology to describe its concepts. Understanding these terms is essential for working with classes, objects, and inheritance in Python. Core OOP Terms Class A user-defined blueprint for creating objects that defines attributes and methods. Think of it as a template that describes what data and behaviors objects will have ? class Car: wheels = 4 # Class variable def __init__(self, brand): self.brand = brand # Instance ...

Read More

Argument of an Exception in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 5K+ Views

An exception can have an argument, which is a value that provides additional information about the problem. The contents of the argument vary by exception. You capture an exception's argument by supplying a variable in the except clause as follows − Syntax try: # Your operations here pass except ExceptionType as argument: # You can access the exception argument here print(argument) If you write the code to handle a single exception, you can have a variable follow the name ...

Read More

Longest Palindromic Substring in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 11K+ Views

Finding the longest palindromic substring in a string is a classic dynamic programming problem. A palindrome reads the same forwards and backwards, like "BAB" or "RACECAR". We'll use a 2D table to track which substrings are palindromes. Algorithm Overview The approach uses dynamic programming with these steps ? Create a 2D boolean matrix where dp[i][j] represents if substring from index i to j is a palindrome Initialize single characters as palindromes (diagonal elements = True) Check substrings of increasing length, starting from length 2 For each substring, check if first and last characters match and the ...

Read More

Longest Substring Without Repeating Characters in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 8K+ Views

In Python, finding the longest substring without repeating characters is a classic string problem. We can solve this using different approaches: the Brute Force method which checks all possible substrings, and the more efficient Sliding Window technique using either a set or dictionary to track character positions. Common Methods The main approaches to find the longest substring without repeating characters are: Brute Force: Checks all possible substrings and verifies if they have unique characters. Sliding Window with Set: Uses a set to track characters in the current window and adjusts window boundaries dynamically. ...

Read More

Add Two Numbers in Python

gireesha Devara
gireesha Devara
Updated on 25-Mar-2026 3K+ Views

Adding two numbers in Python is one of the most basic tasks, where we need to combine their values to get a total. In this article, we will explore different ways to add two numbers in Python using various operators and built-in functions. Using Arithmetic Operator To add two numerical values in Python, we can use the addition operator, represented by the "+" symbol. It is one of the arithmetic operators in Python that performs the addition operation. Example Here is the basic example that adds the two numbers using the addition operator (+) − ...

Read More

Locating Modules in Python

gireesha Devara
gireesha Devara
Updated on 25-Mar-2026 2K+ Views

Locating modules in Python refers to the process of how Python finds and loads a module into our current program when we are trying to import it. Python's standard library comes with a large number of modules that we can use in our programs with the import statement. Module Search Process When you write an import statement like import mymodule, the Python interpreter searches for the module in the following sequence ? The current directory − Python first checks the directory of the current script. PYTHONPATH Environment Variable ...

Read More

Variable-length arguments in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 6K+ Views

You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable-length arguments and are not named in the function definition, unlike required and default arguments. Syntax Syntax for a function with non-keyword variable arguments is this − def functionname([formal_args, ] *var_args_tuple): "function_docstring" function_suite return [expression] An asterisk (*) is placed before the variable name that holds the values of all nonkeyword variable arguments. This tuple remains empty if no additional arguments ...

Read More

Required arguments in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 9K+ Views

Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition. To call the function printme(), you definitely need to pass one argument, otherwise it gives a syntax error as follows ? Example with Missing Required Argument # Function definition is here def printme(str): "This prints a passed string into this function" print(str) return # Now you can call printme function printme() When ...

Read More

Pass by reference vs value in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 12K+ Views

In Python Call by Value and Call by Reference are two types of generic methods to pass parameters to a function. In the Call-by-value method, the original value cannot be changed, whereas in Call-by-reference, the original value can be changed. Call by Value in Python When we pass an argument to a function, it is stored locally (in the stack memory), i.e the scope of these variables lies within the function and these will not affect the values of the global variables (variables outside function). In Python, "passing by value" is possible only with the immutable types ...

Read More

Calling a Function in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 580 Views

Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code. Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is the example to call printme() function ? Example # Function definition is here def printme(str): """This prints a passed string into this function""" print(str) return # Now you can call printme ...

Read More
Showing 6781–6790 of 8,549 articles
« Prev 1 677 678 679 680 681 855 Next »
Advertisements