Erinevus lehekülje "JavaPython:Operaatorid" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
(Uus lehekülg: '{{JavaPython-sisukord}}')
 
 
1. rida: 1. rida:
 
{{JavaPython-sisukord}}
 
{{JavaPython-sisukord}}
 +
 +
The following operators are basically the same in Python and Java:
 +
 +
    .  +  -  *  /  <  <=  ==  !=  >=  >  +=  -=  *=  /=  &  |  ^  ~  <<  >>
 +
When applied to objects, the Java == and != operators act like Python's is and is not operators, which is usually not what is wanted (especially for Strings). Equality testing should be done with the obj1.equals(obj2) method.
 +
 +
The % (mod) operator behaves the same for positive integers, but differently for negative integers.
 +
 +
Python's isinstance(object, Class) function is the equivalent of Java's object instanceof Class operator.
 +
 +
The Java equivalents of Python's and, or, and not are &&, ||, and !, respectively. There are no equivalents for in and not in.
 +
 +
Java has ++, to increment by one, and --, to decrement by one. These can be either prefix or postfix, and should be used only as statements, not as part of an expression. Java also has the expression condition ? valueIfTrue : valueIfFalse to choose between two values.
 +
 +
== Näide ==

Viimane redaktsioon: 2. veebruar 2016, kell 10:56

Java vs Python

The following operators are basically the same in Python and Java:

   .  +  -  *  /  <  <=  ==  !=  >=  >  +=  -=  *=  /=  &  |  ^  ~  <<  >>

When applied to objects, the Java == and != operators act like Python's is and is not operators, which is usually not what is wanted (especially for Strings). Equality testing should be done with the obj1.equals(obj2) method.

The % (mod) operator behaves the same for positive integers, but differently for negative integers.

Python's isinstance(object, Class) function is the equivalent of Java's object instanceof Class operator.

The Java equivalents of Python's and, or, and not are &&, ||, and !, respectively. There are no equivalents for in and not in.

Java has ++, to increment by one, and --, to decrement by one. These can be either prefix or postfix, and should be used only as statements, not as part of an expression. Java also has the expression condition ? valueIfTrue : valueIfFalse to choose between two values.

Näide