Found 34490 Articles for Programming

Multiple .java files

Mohammad Mohtashim
Updated on 30-Jul-2019 22:30:22

298 Views

You can use Advanced IDE to use multiple files. Here is the link:https://www.tutorialspoint.com/online_java_compiler.php

How to convert a string to a integer in C

Pythonista
Updated on 27-Jan-2020 12:41:27

456 Views

First extract characters from left bracket '(' using strchr() function.char *name="The Matrix(1999)"; char *ps; ps=strchr(name,'(');Then add each character within brackets () to an char arraychar y[5]=""; int  p; for (p=1;p

How do we include the direction of text display in HTML?

Rishi Rathor
Updated on 24-Jun-2020 07:36:47

137 Views

Use the dir attribute in HTML, to add the direction of the text.ExampleYou can try to run the following code to include the direction of text display in HTML −           This is demo text from left-to-right.       This is demo text from right-to-left.    

How to Find HCF or GCD using Python?

Vikram Chiluka
Updated on 28-Oct-2022 11:31:48

1K+ Views

In this article, we will show you how to find the HCF (Highest Common Factor) or GCD (Greatest Common Factor) in Python. Below are the various methods to accomplish this task: Using For Loop Using Euclidean Algorithm Using While Loop Using Recursion(Naive method) Handling Negative Numbers in HCF What is H.C.F. or G.C.D? The largest positive integer that perfectly divides the two given numbers is known as the highest common factor (H.C.F.) or greatest common divisor (G.C.D.). Example - The HCF of 12 and 14, is 2. Using For Loop Algorithm (Steps) Following are the Algorithm/steps to be followed to ... Read More

What are Ordered dictionaries in Python?

Jayashree
Updated on 02-Mar-2020 10:21:48

406 Views

An OrderedDict is a dictionary subclass that remembers the order in which its contents are added, supporting the usual dict methods.If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end.>>> from collections import OrderedDict >>> d = {'banana': 3, 'apple':4, 'pear': 1, 'mango': 2} >>> od=OrderedDict(d.items()) >>> od OrderedDict([('banana', 3), ('apple', 4), ('pear', 1), ('mango', 2)]) >>> od=OrderedDict(sorted(d.items())) >>> od OrderedDict([('apple', 4), ('banana', 3), ('mango', 2), ('pear', 1)]) >>> t=od.popitem() >>> t ('pear', 1) >>> od=OrderedDict(d.items()) >>> t=od.popitem() >>> t ('mango', 2)

Where are operators mapped to magic methods in Python?

Vikram Chiluka
Updated on 09-Nov-2022 08:05:07

305 Views

In this article, we will explain to you where are operators mapped to magic methods in python. Python Magic methods are special methods that begin and end with double underscores. They are also known as dunder methods. Magic methods are not intended to be invoked directly by you, but rather invocation occurs by the class on a specific action. When you use the + operator to add two numbers, the __add__() method is called internally. Many magic methods in Python are defined by built−in classes. To get the number of magic methods inherited by a class, use the dir() function. ... Read More

What is the difference between operator and method on Python set?

Jayashree
Updated on 02-Mar-2020 10:21:19

351 Views

Python's set object represents built-in set class. Different set operations such as union, intersection, difference and symmetric difference can be performed either by calling corresponding methods or by using operators.Union by method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.union(s2) {1, 2, 3, 4, 5, 6, 7, 8} >>> s2.union(s1)  {1, 2, 3, 4, 5, 6, 7, 8}Union by | operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1|s2  {1, 2, 3, 4, 5, 6, 7, 8}Intersection by method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.intersection(s2) {4, 5} >>> s2.intersection(s1)  {4, 5}Intersection & operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1&s2 {4, 5} >>> s2&s1  {4, 5}Difference method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.difference(s2) {1, 2, 3} >>> s2.difference(s1)  {8, 6, 7}Difference - operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1-s2 {1, 2, 3} >>> s2-s1  {8, 6, 7}

How will you explain Python Operator Overloading?

Jayashree
Updated on 30-Jul-2019 22:30:22

144 Views

Every class in Python, whether built-in or user defined is inherited from object class. The object class has a number of properties whose name is preceded and followed by double underscores (__). Each of these properties is a wrapper around a method of same name. Such methods are called special or magic methods.The magic methods __lt__(), __gt__(), __eq__(), __ne__(), etc. are overridden in a class to overload == and != operators respectively.

How to write string functions in Java?

Pythonista
Updated on 30-Jul-2019 22:30:22

85 Views

1) take a string from the user and check contains atleast one digit or not:Extract character array from string using toCharArray() method. Run a for loop over each character in array and test if it is a digit by static method isDigit() of character classpublic static boolean chkdigit(String str) { char arr[]=str.toCharArray(); for (char ch:arr) { if (Character.isDigit(ch)) { return true; } } return false; }2.) take ... Read More

How to perform square root without using math module in Python?

Vikram Chiluka
Updated on 28-Aug-2023 12:39:09

29K+ Views

In this article, we will show you how to perform square root without using a math module in Python. Below are the various methods to accomplish this task: Using exponential operator ** Using Mathematical Logic Using exponential operator ** Without using the math module, the simplest approach to find the square root of a number in Python is to use the built-in exponential operator ** (It is an exponent operator because it calculates the power of the first operand to the power of the second operand). Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired ... Read More

Advertisements