Friday, November 11, 2016

Jython operators

Welcome back to Jython learning blog again. today I have explored the operators how they can be used in Jython for wsadmin. This simple experiments would give you a base for building automation scripts in your projects.

How can Jython deals with Arithmetic operators


wsadmin>x,y = 10, 20
wsadmin>print x, y
10 20
wsadmin>x+y
30
wsadmin>x+y+30
60
wsadmin>y-x
10
wsadmin>x-y
-10
wsadmin>x*y
200
wsadmin>x**2
100
wsadmin>y/x
2
wsadmin>y%x
0

How to use Jython Comparison operators


Numeric comparison in Jython
 wsadmin>10>1
1
wsadmin>20<34
1
wsadmin>20<2
0
wsadmin>10<10
0
wsadmin>10<=10
1



Tuple comparison in Jython
wsadmin>'app_server1' in ('app_server1','app_server2','ejb_server1','ejb_server2')
1
wsadmin>servers_list=('app_server1','app_server2','ejb_server1','ejb_server2')
wsadmin>'appserver1' in servers_list
0


String comparison in Jython
wsadmin>'dmgr'=='dmgr'
1




Char comparison in Jython
wsadmin>'t'=='t'
1
wsadmin>'t'=='T'
0



List comparison in Jython
wsadmin>['dev_cell01',20]==['dev_cell01',20]
1
wsadmin>['dev_cell01',20]==[20,'dev_cell01']
0


Dictionaries comparison in Jython
wsadmin>{'appserver1':8001}=={'appserver1':8001}
1
wsadmin>server_dict={'appserver1':8001}
wsadmin>{'appserver1':8001}==server_dict
1
wsadmin>server_dict=={'appserver2':8001}
0

How can Jython Relational operators simplify your scripts

wsadmin>x>=10
1
wsadmin>x>=10 and y==20
1
wsadmin>x>10 or y==20
1
wsadmin>x>10
0
wsadmin>not x>10
1
wsadmin>not x>=10
0