Found 34484 Articles for Programming

Explain function of % operator in Python.

Pythonista
Updated on 26-Feb-2020 07:37:20

357 Views

In Python % is an arithmetic operator that returns remainder of division operation. It is called modulo or remainder operator and operates upon numeric operands except complex numbers>>> a=10 >>> a%3 1 >>> a%5 0 >>> b=12.5 >>> b%2.5 0.0 >>> b%2 0.5

What is function of ^ operator in Python

Pythonista
Updated on 26-Feb-2020 07:37:55

371 Views

In Python, ^ is called EXOR operator. It is a bitwise operator which takes bits as operands. It returns 1 if one operand is 1 and other is 0.Assuming a=60 (00111100 in binary) and b=13 (00001101 in binary) bitwise XOR of a and b returns 49 (00110001 in binary)>>> a=60 >>> bin(a) '0b111100' >>> b=a^2 >>> bin(b) '0b111110' >>> a=60 >>> bin(a) '0b111100' >>> b=13 >>> bin(b) '0b1101' >>> c=a^b >>> bin(c) '0b110001'

What does the >> operator do in Python?

Pythonista
Updated on 26-Feb-2020 07:38:32

327 Views

It is a bitwise right shift operator. The bit pattern is shifted towards right by number of places stipulated by operand on right. Bits on left are set to 0For example a=60 (00111100 in binary), a>>2 will result in 15 (00001111 in binary)>>> a=60 >>> bin(a)result #39;0b111100' >>> b=a>>2 >>> bin(b) '0b1111'

What is "not in" operator in Python?

Pythonic
Updated on 09-Sep-2023 15:12:50

5K+ Views

In Python, 'not in' membership operator evaluates to true if it does not finds a variable in the specified sequence and false otherwise. For example >>> a = 10 >>> b = 4 >>> l1 = [1,2,3,4,5] >>> a not in l1 True >>> b not in l1 False Since 'a' doesn't belong to l1, a not in b returns True. However, b can be found in l1, hence b not in l1 returns False

Does Python have a ternary conditional operator?

Malhar Lathkar
Updated on 26-Feb-2020 07:28:43

162 Views

Ternary operator was added in Python 2.5. Its syntax is:Syntaxx if expr==True else yExampleFollowing example illustrates usage>>> percent=59 >>> 'pass' if percent>=50 else 'fail' 'pass' >>> percent=45 >>> 'pass' if percent>=50 else 'fail' 'fail'

Converting Strings to Numbers and Vice Versa in Java.

Sravani S
Updated on 26-Feb-2020 09:51:01

1K+ Views

Java lang package provides Integer class which has methods to convert an integer to String and vice versa. You can convert a String to an integer using the parseInt() method and Integer to String using the toString() method.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "1212";       int num = Integer.parseInt(str);       System.out.println(num);       String st = Integer.toString(num);       System.out.println();    } }Output1212

How to Convert Double to String to Double in Java?

V Jyothi
Updated on 26-Feb-2020 09:51:54

207 Views

Java lang package provides a Double class which has methods to convert Double to String and vice versa. You can convert a String to a double using the parseDouble() method and double to String using the toString() methodExampleLive Demopublic class StringDouble {    public static void main(String args[]){       Double data1 = 2.2;       String str = Double.toString(data1);       System.out.println(str);       Double data2 = Double.parseDouble(str);       System.out.println(data2);    } }Output2.2 2.2

Data Conversion Using valueOf() In Java.

Priya Pallavi
Updated on 26-Feb-2020 09:53:23

145 Views

Java String class provides several variants of valueOf() method. These accept various data types and convert them into String.ExampleLive Demopublic class Sample {    public static void main(String args[]){       int i = 200;       float f = 12.0f;       char c = 's';       char[] ch = {'h', 'e', 'l', 'l', 'o'};       String data = String.valueOf(i);       System.out.println(String.valueOf(i));       System.out.println(String.valueOf(f));       System.out.println(String.valueOf(c));       System.out.println(String.valueOf(ch));    } }Output200 12.0 s hello

What is the difference between String.valueOf() and toString() in Java?

Nikitha N
Updated on 26-Feb-2020 09:56:04

1K+ Views

The toString() method of the String class returns itself a string.ExampleLive Demoimport java.io.*; public class Test {    public static void main(String args[]) {       String Str = new String("Welcome to Tutorialspoint.com");       System.out.print("Return Value :");       System.out.println(Str.toString());    } }OutputReturn Value :Welcome to Tutorialspoint.comThe value of method variants of the String class accepts different variables such as integer, float, boolean etc.. and converts them into String.ExampleLive Demopublic class Sample {    public static void main(String args[]){       int i = 200;       float f = 12.0f;       ... Read More

Java string case change sample code examples.

Abhinanda Shri
Updated on 26-Feb-2020 09:49:50

78 Views

You can change the cases using the toUpperCase() and toLowerCase() methods of the String class.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "Hello how are you";       String strUpper = str.toUpperCase();       System.out.println("Lower to upper : "+strUpper);       String strLower = str.toLowerCase();       System.out.println("Upper to lower : "+strLower);    } }OutputLower to upper : HELLO HOW ARE YOU Upper to lower : hello how are you

Advertisements