Download Jython Installer from the official website
http://www.python.org/download/
And start executing the programs below.
You should get a feel of the Jython scripting language once you execute them.
This is the first part, ill add more scripts sometime later.
Maybe later
Your comments are very valuable to us, feel free to provide any feedback.
# Simple Hello World in Python
>>> print “Hello World”
Hello World
# Adding two numbers in Python
>>> 12+5
17
>>> 14 + 4.5
18.5
# Numberic Operations in Python
>>> 2 + 2*2
6
>>> (12+5) * 3
51
>>> a=34+2
>>> print a
36
# Boolean operators in Python
>>> True or False
True
>>> not ( True or False )
False
>>> True * 10
10
>>> 0 and 1
0
>>> 0 or 1
1
>>> 12 > 3
True
>>> 10 !=12
True
>>> 10 <=10
True
>>> a= “Faisal”
>>> b= “Joy”
>>> a == b
False
# String operations in Python
>>> a=”20?
>>> type (a)
>>> b= int(a)
>>> type(b)
>>> a =”Joy”
>>> b = “Faisal”
>>> a + ” ” + b
‘Joy Faisal’
>>> print a*3
JoyJoyJoy
>>> s = a+b
>>> s[0]
‘J’
>>> s[0:3]
‘Joy’
>>> s[6:]
’sal’
>>> len(s)
9
>>> ‘F’ in s
True
>>> “Fai” in s
True
>>> s=”T” + s[1:]
>>> s
‘ToyFaisal’
>>> s.count( ‘a’ )
2
>>> s.count( “ai” )
1
>>> s.find(“ai”)
4
>>> one=’1′
>>> one.isdigit()
True
>>> su = s.upper()
>>> su
‘TOYFAISAL’
>>> s.rjust(10)
‘ ToyFaisal’
>>> s.replace(” T”,”J”)
‘JoyFaisal’
# List in Python
>>> a= [1.0,2,3,”4″,5]
>>> a
[1.0, 2, 3, ‘4’, 5]
>>> type(a)
>>> a[1]
2
>>> a[-1]
5
>>> a[1:2]
[2]
>>> b = a + [“67”,8]
>>> b
[1.0, 2, 3, ‘4’, 5, ’67’, 8]
>>> b[4]=”Sixty Seven”
>>> b
[1.0, 2, 3, ‘4’, ‘Sixty Seven’, ’67’, 8]
>>> b[4] = [6,7]
>>> b
[1.0, 2, 3, ‘4’, [6, 7], ‘67′, 8]
>>> b[3:4] =[]
>>> b
[1.0, 2, 3, [6, 7], ‘67′, 8]
>>> len(b)
6
>>> 3 in b
True
# List operations in Python
>>> b.index(8)
5
>>> b.append(“Nine”)
>>> b
[1.0, 2, 3, [6, 7], ‘67′, 8, ‘Nine’]
>>> c=[10,11]
>>> b.append(c)
>>> b
[1.0, 2, 3, [6, 7], ‘67′, 8, ‘Nine’, [10, 11]]
>>> b.pop()
[10, 11]
>>> b
[1.0, 2, 3, [6, 7], ‘67′, 8, ‘Nine’]
>>> b.sort()
>>> b
[1.0, 2, 3, 8, [6, 7], ‘67′, ‘Nine’]
>>> b.reverse()
>>> b
[‘Nine’, ’67’, [6, 7], 8, 3, 2, 1.0]
# Converting strings to list in Python
>>> d=”uvwxyz”
>>> e=list(d)
>>> e
[‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’]
>>> e.reverse()
>>> e
[‘z’, ‘y’, ‘x’, ‘w’, ‘v’, ‘u’]
>>> f= “”.join(e)
>>> f
‘zyxwvu’
>>> g = “,”.join(e)
>>> g
‘z,y,x,w,v,u’
>>> h =” Joy and Faisal “
>>> i = h.split()
>>> i
[‘Joy’, ‘and’, ‘Faisal’]
>>> “-”.join(i)
‘Joy-and-Faisal’
Stay tuned…….
Hi Faisal these Perl and python scripts for Beginners are very very good. Keep it up your work. Really appreciated.
Thanks Viswa!