__author__ = 'mare' def Times(a, b): return a*b print(Times) #print( Times(10, 10) ) #100 myTimes = Times; r = myTimes(10, 10); print( r ) #100 #return def setValue(newValue): x = newValue retval = setValue(10) print( retval ) #None def swap(x, y): return y, x swap(1,2) #(2,1) a, b = swap(1,2) #a = 2, b = 1 x = swap(1,2) print( type(x) ) # #more complex function def intersect(prelist, postlist): retlist = [] for x in prelist: if x in postlist and x not in retlist: retlist.append(x) return retlist list1 = "SPAM" list2 = "AM" list3 = intersect(list1, list2) print(list3) #['A', 'M'] #parameters a=10 b=20 def sum1(x,y): return x+y print( sum1(a,b) ) #30 x = 10 def sum2(x,y): x = 1 return x+y print( sum2(x, b), x ) #21 10 def change(x): x[0] = 'H' wordlist = ['J', 'A', 'M' ] change(wordlist) print(wordlist) #['H', 'A', 'M'] def change(x): x = x[:] x[0] = 'H' return None wordlist[0] = 'J' change(wordlist) print(wordlist) #['J', 'A', 'M'] #scoping rule x=1 def func2(a): x=2 return a+x print( func2(10) ) #12 def func3(a): global x x = 20 return x+a print( func3(10 ), x) #30 20 dir( __builtins__ ) #you can see inner function names #arguments def Times(a=10, b=20): return a+b print( Times() ) #30 print( Times(5) ) #25 #keyword arguments def connectURI( server, port): str = "http://" + server + ":" + port return str print( connectURI("test.com", "800" )) print( connectURI(port="8080", server="test.com")) #http://test.com:800 #http://test.com:8080 #variable argument def test(*args): print( type(args) ) test(1,2) # def union2(*ar): res = [] for item in ar: for x in item: if not x in res: res.append(x) return res print( union2( "HAM", "EGG", "SPAM" ) ) print( union2("GIR", "Generation", "gee") ) #['H', 'A', 'M', 'E', 'G', 'S', 'P'] #['G', 'I', 'R', 'e', 'n', 'r', 'a', 't', 'i', 'o', 'g'] def userURIBuilder(server, port, **user): str = "Http://" + server + ":" + port + "/?" for key in user.keys(): str += key + "=" + user[key] + "&" return str s = userURIBuilder("Test.com", "8080", id='userid', passwd='1234') print(s) #Http://Test.com:8080/?id=userid&passwd=1234& #lambda function g = lambda x, y : x*y g(2,3) #6 (lambda x: x*x)(3) #9 #recursive function call def factorial(x): if x == 1: return 1 return x*factorial(x-1) factorial(10) #3628800 #pass #while True: # pass #control + c if you stop class temp: pass #help def factorial(x): "return factorial of n, ...." if x == 1: return 1 return x*factorial(x-1) #help( factorial) #return factorial of n, .... #iterator """ for element in [1, 2, 3]: for element in (1, 2, 3): for key in {'one':1, 'two':2}: for char in "123": for line in open("myfile.txt") read line by line in the file """ #generator def reverse(data): for index in range(len(data) -1, -1, -1): yield data[index] for char in reverse('golf'): print( char) #f #l #o #g #enumerate for i, season in enumerate(['spring', 'summer', 'fall', 'winter']): print(i, season) #0 spring #1 summer #2 fall #3 winter #iter s='abc' it = iter(s) print(next(it)) #a print(next(it)) #b print(next(it)) #c #print(next(it)) -> error
1/23/2014
(python study) about function (example source code)
Subscribe to:
Post Comments (Atom)
-
fig 1. Left: set 4 points (Left Top, Right Top, Right Bottom, Left Bottom), right:warped image to (0,0) (300,0), (300,300), (0,300) Fi...
-
As you can see in the following video, I created a class that stitching n cameras in real time. https://www.youtube.com/user/feelmare/sear...
-
In past, I wrote an articel about YUV 444, 422, 411 introduction and yuv rgb converting example code. refer to this page -> http://feel...
-
The MNIST dataset is a dataset of handwritten digits, comprising 60 000 training examples and 10 000 test examples. The dataset can be downl...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
In the YUV color format, Y is bright information, U is blue color area, V is red color area. Show the below picture. The picture is u-v col...
-
Proceed with the project to update the 2012 version, or that you must reinstall Visual Studio 2010. If you are using Visual Studio 2...
-
Created Date : 2010.8 Language : C/C++ Tool : Microsoft Visual C++ 6.0 Library & Utilized : STL Reference : A* i...
-
Background subtractor example souce code. OpenCV support about 3 types subtraction algorithm. Those are MOG, MOG2, GMG algorithms. Det...
-
Video stabilization example source code. The principle is like that... Firstly, to obtain 2 adjacent images extract good feature to t...
No comments:
Post a Comment