Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Define Jython Functions Example

#defining function
def area(l,b):
   area = l*b
   print "area = ",area
   return area

#calling function
length = 10
breadth = 20
#calling function and obtaining its reurned value
result = area(length, breadth)
print "value returned by function : ", result

Defining Functions with two Arguments in Jython

#defining function with two arguments
def area(l,b):
   area = l*b
   print "area = ",area
   return

#calling function
length = 10
breadth = 20
#with two arguments. This is OK
area(length, breadth)
#only one argument provided. This will throw TypeError
area(length)

Range Function Program in Jython

for num in range(5):
   print num

For Loop Program in Jython

#each letter in string
for letter in 'Python':
   print 'Current Letter :', letter

WHILE Loop Program in Jython

count = 0
while count<10:
   count = count+1
   print "count = ",count
print "Good Bye!"

Jarray Class in Jython

my_seq = (1,2,3,4,5)
from jarray import array
arr1 = array(my_seq,'i')
print arr1
myStr = "Hello Jython"
arr2 = array(myStr,'c')
print arr2

Java Collection Types Program in Jython

import java.util.ArrayList as ArrayList
arr = ArrayList()
arr.add(10)
arr.add(20)
print "ArrayList:",arr
arr.remove(10) #remove 10 from arraylist
arr.add(0,5) #add 5 at 0th index
print "ArrayList:",arr
print "element at index 1:",arr.get(1) #retrieve item at index 1
arr.set(0,100) #set item at 0th index to 100
print "ArrayList:",arr

Date Program in Jython

from java.util import Date
d = Date()
print d

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.