Niharika Aitam

Niharika Aitam

133 Articles Published

Articles by Niharika Aitam

133 articles

Program to check if a string contains any special character

Niharika Aitam
Niharika Aitam
Updated on 02-Apr-2026 4K+ Views

Python provides several methods to check if a string contains special characters. Special characters are any non-alphanumeric characters like punctuation marks, symbols, or other characters that are not letters or numbers. Using Regular Expressions The re module provides powerful pattern matching capabilities. The pattern [^a-zA-Z0-9\s] matches any character that is not a letter, digit, or whitespace ? Example import re def has_special_char(s): pattern = r'[^a-zA-Z0-9\s]' if re.search(pattern, s): return True return False # ...

Read More

Print objects of a class in Python

Niharika Aitam
Niharika Aitam
Updated on 02-Apr-2026 4K+ Views

An object is the part of Object Oriented Programming (OOP), which is an instance of a class. The class is the blueprint or template that specifies the methods and properties of that class. When we create an object of a class, it contains all the instance methods and variables related to that particular object. By default, printing an object shows its memory address, but we can customize this behavior using special methods. Using __str__ Method The __str__ method provides a human-readable string representation of an object. It's automatically called when we use print() or str() on an object ...

Read More

How to Convert Bytearray to Hexadecimal String using Python?

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 4K+ Views

A hexadecimal string is a textual representation of data using base-16 notation, combining digits 0-9 and letters A-F. Each hexadecimal character represents 4 bits, making it useful for displaying binary data in a compact, human-readable format. Python provides several methods to convert a bytearray to hexadecimal string. What is a Bytearray? A bytearray is a mutable sequence of bytes in Python. Unlike strings, bytearrays can be modified after creation and are ideal for handling binary data like images, network packets, or cryptographic operations. Each element is an integer from 0 to 255. # Creating a bytearray ...

Read More

Discuss the effect of changing the plot\'s aspect ratio on the visual representation of data.

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 202 Views

The aspect ratio of a plot refers to the ratio of the width to the height of the plotting area. It is a crucial parameter in data visualization as it determines the shape and proportions of the plot, which directly affects how the data is visually represented. For example, in a square plot the aspect ratio would be 1:1, which means the width is equal to the height. In contrast, if the width is twice the height, then the aspect ratio would be 2:1 and the plot would be wider horizontally. Let's explore the effects of changing the plot's ...

Read More

Python - Consecutive Character Maximum difference

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 344 Views

Consecutive Character Maximum Difference refers to finding the maximum absolute difference between the ASCII values of consecutive characters in a string. It is used to measure the maximum "gap" or "jump" in the character sequence based on their ASCII values. In Python, each character in a string is represented internally as a Unicode code point, and the corresponding ASCII value can be obtained using the ord() function. The ASCII values of consecutive characters can be compared to calculate the absolute difference between them. Basic Example Consider the string "abcdefg" − The ...

Read More

Python - Concatenate N consecutive elements in String list

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 286 Views

Concatenation is the process of combining two or more strings, sequences, or data structures together to create a single larger entity. In Python, we often need to concatenate N consecutive elements from a string list, which can be achieved using several approaches. In many programming languages such as Python, the concatenation operation is typically represented using the + operator. When we use the + operator with strings, it performs string concatenation, joining the strings together in the order they appear. Basic String Concatenation Here's an example of string concatenation in Python ? string1 = "Welcome ...

Read More

How to Convert Character Matrix to single String using Python?

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 553 Views

Converting a character matrix to a single string in Python means taking a 2D representation of characters such as a list of lists or a NumPy array and combining all the characters into a single string. The order of the characters in the resulting string is determined by the arrangement of characters in the matrix. Basic Approach Using String Concatenation The simplest way to convert a character matrix is by using a custom function that iterates through each row and joins the characters ? def matrix_to_string(matrix): rows = [''.join(row) for row in ...

Read More

How to Concatenate dictionary value lists in Python

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 1K+ Views

Dictionary value concatenation involves combining lists that are stored as values in a Python dictionary into a single list. This is useful when you need to aggregate data from multiple dictionary entries or flatten nested list structures. Understanding Dictionary Value Lists When working with dictionaries containing lists as values, you often need to merge these lists into one comprehensive list ? # Example dictionary with list values data = { "fruits": ["apple", "banana"], "vegetables": ["carrot", "spinach"], "grains": ["rice", "wheat"] } print("Original dictionary:", data) ...

Read More

How to Concatenate All Records in Python?

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 244 Views

Concatenation is the process of combining two or more strings, lists, or other sequences into a single entity. It involves joining the elements of the sequences in a specific order to create a new sequence or string. In the context of strings, concatenation means appending one string to the end of another, resulting in a longer string. For example, if we have two strings, "Hello" and "World", concatenating them would produce the string "HelloWorld". The concatenation operator (+) or the str.join() method is commonly used for string concatenation in Python. Similarly, concatenation can be applied to other sequence ...

Read More

Is Python Compiled or Interpreted?

Niharika Aitam
Niharika Aitam
Updated on 27-Mar-2026 1K+ Views

Python is an interpreted programming language. However, when we want to check whether Python is compiled or interpreted can be a bit confusing. Let's dive into a detailed explanation to understand the inner workings of Python's execution model and how it combines aspects of compilation and interpretation. Interpreted languages are typically executed directly by an interpreter without a separate compilation step. In contrast, compiled languages go through a compilation process where the source code is translated into machine code or an intermediate representation before execution. However, Python's execution model is a blend of both interpretation and compilation. At ...

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