Inheritance vs Instantiation for Python Classes

Akshitha Mote
Updated on 30-Apr-2025 16:33:09

11K+ Views

In Python, inheritance is the capability of one class to derive or inherit the properties from another class. The class that derives properties is called the derived class or child class, and the class from which the properties are being derived is called the base class or parent class. In other words, inheritance refers to defining a new class with little or no modification to an existing class. Following is the syntax of the inheritance - class A: #class A (base class) pass class ... Read More

Different Types of Quotes in Python

Akshitha Mote
Updated on 30-Apr-2025 16:19:16

7K+ Views

In Python, strings can be defined using single quotes ('), double quotes ("), or triple quotes (''' or """). For example, 'Hello' is a valid string. There are different types of quotes in Python. Each quotation is used in different scenarios as per the requirement. The following are the different types of quotations that we can use in the Python programming language. Single quotes Double quotes ... Read More

Find the Unique Number in Java

AYUSH MISHRA
Updated on 30-Apr-2025 15:21:44

4K+ Views

In this problem, we are given an array of integers. In the given array, each element occurs two times except one element, which occurs only once. We have to find the number that appears only once. In this article, we are going to learn how we can find the number that appears once, and all other numbers appear twice in Java. Scenario 1 All other numbers except 4 occur twice, so 4 is the only number that appears only once. Input: [ 1, 2, 3, 3, 2, 4, 1, 5, 5] Output: 4 Scenario 2 All other numbers except ... Read More

C++ Program to Rotate Array Left by One Position

AYUSH MISHRA
Updated on 30-Apr-2025 14:36:53

9K+ Views

Rotating an array means shifting the elements of an array in a specific direction while maintaining their relative order. For example, if the array {6, 12, 18, 24, 30} is rotating it left once will result in {12, 18, 24, 30, 6}. In this article, we are given an array and need to shift all elements one step to the left, with the first element moving to the last position. Example Here is an example of left rotation of elements in array by one place. Input: array = {5, 10, 15, 20, 25} Output: array = {10, 15, ... Read More

Difference Between dict.items() and dict.iteritems() in Python

Akshitha Mote
Updated on 30-Apr-2025 14:24:04

509 Views

In Python, the dict.items() and dict.iteritems() methods are used to return a dictionary. The only difference is that the dict.items() returns the keys and value pairs in the form of a list of tuple pairs, whereas the dict.iteritems() returns an iterator over the dictionary’s (key, value) tuple pairs. The dict.items() and dict.iteritems() functions are present in Python 2.x versions. The dict.iteritems() function is omitted from the Python 3.x version. Example - 'dict.items()' in Python 2.x version Following is an execution of the dict.items() in Python 2.x version - my_dict={1:'one', 2:'two', 3:'three', 4:'four'} print(my_dict.items()) Output Following is the output ... Read More

Find Square Root of Complex Numbers in Python

Chandu yadav
Updated on 30-Apr-2025 13:06:05

660 Views

Complex numbers are numbers that have both real and imaginary components in the structure,  a+bi. You can find the square root of complex numbers in Python using the cmath module. This module in Python is exclusively used to deal with complex numbers.Square Root of Complex Numbers Using cmath.sqrt() The cmath.sqrt() function is a part of Python's cmath module, that takes a number which is an integer or float (real or complex) and returns the complex square root of x. Below are some examples of scenarios where the function can be used - Example - Basic Complex Number In the below ... Read More

Implement Graham Scan Algorithm to Find Convex Hull in C++

Nitya Raut
Updated on 29-Apr-2025 19:43:58

4K+ Views

A convex hull is the smallest convex polygon with maximum area and minimum perimeter that encloses all the given points in a 2D plane. In this article, we will learn how to write C++ program to implement Graham Scan Algorithm to find convex hull. The objective of this problem is to take a set of x and y coordinates of a 2d plane as input, and display coordinate point from the set which are part of convex hull. // Input Set of points: {0, 0}, {1, 1}, {2, 2}, {2, 0}, {1, 2}, {0, 2} // Output Boundary ... Read More

Implement Jarvis March to Find the Convex Hull in C++

Nitya Raut
Updated on 29-Apr-2025 19:42:07

1K+ Views

A convex hull is the smallest convex polygon with maximum area and minimum perimeter that encloses all the given points in a 2D plane. In this article, we will learn how to write C++ program to implement Jarvis March Algorithm to find a convex hull. The objective of this problem is to take a set of x and y coordinates of a 2d plane as input, and display coordinate point from the set which are part of convex hull. // Input Set of points: {0, 0}, {1, 1}, {2, 2}, {2, 0}, {1, 2}, {0, 2} // Output ... Read More

Get List of All Sub-Directories in Current Directory Using Python

Niharikaa Aitam
Updated on 29-Apr-2025 19:21:37

13K+ Views

In Python, when working with files and directories, we may often need to get a list of subdirectories within a specific location, especially the current working directory. In this article, we are going to use the different methods available in Python to get a list of all subdirectories in the current directory. Using os Module While working with files, one of the most widely used approaches is using os module. This module provides a way to interact with the operating system to perform tasks such as navigating directories, reading file structures, and more. In this module, we have a ... Read More

Differences Between GridLayout and GridBagLayout in Java

raja
Updated on 29-Apr-2025 19:16:31

8K+ Views

In Java, a GridLayout puts all the components in a rectangular grid and is divided into equal-sized rectangles, and each component is placed inside a rectangle whereas GridBagLayout is a flexible layout manager that aligns the components vertically and horizontally without requiring that the components be of the same size. Java GridLayout A GridLayout arranges the components in a rectangular grid. It arranges components in the cells, and each cell has the same size. Components are placed in columns and rows. GridLayout(int rows, int columns) takes two parameters that are a column and a row. Syntax The following is the ... Read More

Advertisements