Found 33676 Articles for Programming

How to remove an element from an array in Java

Sreemaha
Updated on 24-Feb-2020 11:11:49

1K+ Views

Following example shows how to remove an element from array. Exampleimport java.util.ArrayList; public class Main {    public static void main(String[] args) {       ArrayList objArray = new ArrayList();       objArray.clear();       objArray.add(0,"0th element");       objArray.add(1,"1st element");       objArray.add(2,"2nd element");       System.out.println("Array before removing an element"+objArray);       objArray.remove(1);       objArray.remove("0th element");       System.out.println("Array after removing an element"+objArray);    } }OutputThe above code sample will produce the following result. Array before removing an element[0th element, 1st element, 2nd element] Array after removing an element[2nd element]

How to create a complex number in Python?

Malhar Lathkar
Updated on 24-Feb-2020 10:04:52

192 Views

Complex number is made up of real and imaginary parts. Real part is a float number, and imaginary part is any float number multiplied by square root of -1 which is defined as j.>>> no=5+6j >>> no.real 5.0 >>> no.imag 6.0 >>> type(no) The resulting object is of complex data type. Python library also has complex() function, which forms object from two float arguments>>> no=complex(5,6) >>> no (5+6j) >>> no.real 5.0 >>> no.imag 6.0 >>> type(no)

How do we evaluate a string and return an object in Python?

Gireesha Devara
Updated on 29-May-2025 11:13:15

1K+ Views

By using the eval() function in Python, we can evaluate a string and return a Python object. The eval() is a Python built-in function that evaluates a string argument by parsing the string as a code expression. eval(expression[, globals[, locals]]) Evaluating a String with Arithmetic Expression? If we pass a string containing an arithmetic expression to the eval() function. First, it parses the expression, then evaluates it, and finally returns an evaluated Python object. Example In the following example, the eval() function evaluates the string formed arithmetic expression and returns an integer object - var = 100 string_EXP_1 ... Read More

How can I convert Python strings into tuple?

Gireesha Devara
Updated on 29-May-2025 11:17:09

5K+ Views

Converting Python String into TupleWe can convert a Python string into tuples by simply mentioning a comma (, ) after the string. This will treat the string as a single element to the tuple. Example Here our string variable “s” is treated as one item in the tuple, which can be done by adding the comma after the string - s = "python" print("Input string :", s) t = s, print('Output tuple:', t) print(type(t)) Following is the output of the above code - Input string : python Output tuple: ('python', ) Using tuple() Function Also, ... Read More

What does the Double Star operator mean in Python?

Gireesha Devara
Updated on 09-Sep-2023 15:22:05

10K+ Views

The double star/asterisk (*) operator has more than one meaning in Python. We can use it as a exponential operator, used as function *kwargs, unpacking the iterables, and used to Merge the Dictionaries. Exponential operator For numeric data the double asterisk (**) is used as an exponential operator. Let's take an example and see how the double star operator works on numeric operands. Example The following example uses double asterisks/star (**) to calculate “a to the power b” and it works equivalent to the pow() function. a = 10 b = 2 result = a ** b print("a**b = ", ... Read More

How to get the size of a list in Python?

Akshitha Mote
Updated on 23-Jun-2025 19:20:39

6K+ Views

In Python, a list is an ordered sequence that can hold several object types, such as integers, characters, or floats. In other programming languages, a list is equivalent to an array. In this article, we need to determine the size of a list, which refers to its length. For instance, the list [10, 20, 30, 40] has a length of 4. Using 'len()' method In Python, the len() method returns the number of items in a list. Example In the following example, we have created an input list and to find the length of the list, it is passed an argument ... Read More

What does the Star operator mean in Python?

Gireesha Devara
Updated on 30-Apr-2025 17:40:21

21K+ Views

The asterisk (*) operator in Python has more than one meaning attached to it. We can use it as a multiplication operator, a repetition operator, for unpacking the iterables, and as a function *args. A single asterisk, as used in a function declaration, allows a variable number of arguments to be passed from the calling environment. Inside the function, it behaves as a tuple. As the multiplication operator Generally, the start (*) operator is used for multiplication purposes. For numeric data, the asterisk (*) is used as a multiplication operator. Let’s take an example and see how the star operator works ... Read More

How to create a dictionary with list comprehension in Python?

Gireesha Devara
Updated on 29-May-2025 11:37:20

747 Views

By using the dict() method in Python, we can create a dictionary with the list comprehension. Following is the syntax of dict() method- dict(**kwarg) Keyword arguments. We can pass one or more keyword arguments. If no keyword argument is passed, then the dict() method will create an empty dictionary object. The syntax for creating a dictionary with list comprehension: dict(list_comprehension) Creating Dictionary using List Comprehension Instead of sending a number of keywords here, we need to send a list of tuples with key-value pairs to the dict() method. Let’s take an example and create a dictionary using a ... Read More

What does ** (double star) and * (star) do for parameters in Python?

Gireesha Devara
Updated on 09-Sep-2023 22:59:21

7K+ Views

While creating a function the single asterisk (*) defined to accept and allow users to pass any number of positional arguments. And in the same way the double asterisk (**) defined to accept any number of keyword arguments. The single asterisk (*) can be used when we are not sure how many arguments are going to be passed to a function and those arguments that are not keywords. The double asterisk (**kwargs) can be used to pass keywords, when we don't know how many keyword arguments will be passed to a function, which will be in a dict named ... Read More

How can I clear or empty a StringBuilder in Java.

mkotla
Updated on 24-Feb-2020 12:21:39

3K+ Views

You can either setLength to be 0 or create a new StringBuilder() instance. See the example below −Examplepublic class Tester {    public static void main(String[] args) {       StringBuilder builder = new StringBuilder();       builder.append("sample");       System.out.println(builder.toString());       builder.setLength(0);       System.out.println(builder.toString());       builder.append("sample");       System.out.println(builder.toString());    } }Outputsample sample

Advertisements