#python supports complex numbers. # append a "j" to a number and it represents the imaginary number. e.g. # 3j means 3*i. #(3,4) can be written as 3+4j ...
#strings are enclosed in double quotes quotes. e.g. a="this and that" print a #multiple lines must have an escape backslash at the end: b="this\n\ and that" ...
# strings can be joined by +. print "this" + " that" # string can be multiplied print "this" *5 # substring extraction is done by appending a bracket # with...
# in Python, list can be done this way: a = [0, 1, 2, 'more',4,5,6] print a # list can be joined with plus sign b = a + [4,5,6] print b # list can be extracted...
# here's a while statement in python. a,b = 0,1 while b < 20: print b a,b = b,a+b ... # here's the same code in perl ($a,$b)=(0,1); while ($b<20) { print $b,...
while programing in Python, one can lookup syntax or info for keywords or modules within Python. In the command line, type python to get into the python...
# here's an example of if statement in python. x=-1 if x<0: print 'neg' elif x==0: print 'zero' elif x==1: print 'one' else: print 'other' # the elif can be...
# this is an example of for statement # the % symbol calculates the remainder # of division. # the range(m,n) function # gives a list from m to n-1. a =...
... And so, in an effort to stop Xah Lee from cross-posting things that have nothing to do with lisp, here is how it's done in Common Lisp. Please post...
... [ snip ] ... Nope. The @ sign tells Perl that the variable is an array. Arrays and lists are two different things in Perl. ... Well, Perl can print lists...
... [ snip ] ... Perl syntax is described in "perldoc perlsyn" ... But as qq is an operator, not a function the best documentation for it is in "perldoc...
fscking yahoo ate all my tabs, so the source is not quite right. how do python programmers avoid this? for a non-munged version, see the *hyper-cliki* page : ...
# the following is a example of defining # a function in Python. def fib(n): """This prints n terms of a sequence where each term is the sum of previous two, ...
# -*- coding: utf-8 -*- # Python # the “filter” function can be used to # reduce a list such that unwanted # elements are removed. # example: def even(n):...
# -*- coding: utf-8 -*- # in Python, there's a special type of # data structure called keyed list. it # is a unordered list of pairs, each # consists of a key...
# python provides some convenient # construct to loop thru lists or # dictionaries # the following construct loops thru a # dictionary each time assiging both ...
# -*- coding: utf-8 -*- # Python # one can write functions, # save it in a file # and later on load the file # and use these functions. # For example, save the...
# -*- coding: utf-8 -*- # Python # once a module is loaded # import mymodule # one can find all the names it # export with dir() import sys print dir(sys) #...
# -*- coding: utf-8 -*- # Python # there are several ways to format # output strings. repr() is for turning a # data into a string form that can be # read back...
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second...
# -*- coding: utf-8 -*- # Python # in Python, one can define a boxed set # of data and functions, which are # traditionally known as "class". # in the...
# -*- coding: utf-8 -*- # Python # some venture into standard modules import os # print all names exported by the module print dir(os) # print the module's...
# -*- coding: utf-8 -*- # Python # suppose you want to walk into a directory, say, to apply a string replacement to all html files. The os.path.walk() rises...
hi all, i've created a webpage to archive all these daily tips. The url is http://xahlee.org/perl-python/python.html past emails will be added in in the next...
in computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } in advanced languages such as...