+ All Categories
Home > Technology > python beginner talk slide

python beginner talk slide

Date post: 14-May-2015
Category:
Upload: jonycse
View: 349 times
Download: 0 times
Share this document with a friend
Description:
python beginner talk slide
Popular Tags:
39
Life is easy with Python ABU ZAHED JONY
Transcript
  • 1.ABU ZAHED JONY

2. Quotes Perl is worse than Python because people wanted it worse - Larry Wall, Creator of Perl Python fits your brain - Bruce Eckel, Author: Thinking in Java Python is an excellent language & makes sensiblecompromises. - Peter Norvig. AI Life is better without brackets 3. About Python very clear, readable syntax portable intuitive object orientation natural expression of procedural code full modularity, supporting hierarchical packages very high level dynamic data types extensive standard libraries and third party modules forvirtually every task extensions and modules easily written in C, C++ (or Java forJython, or .NET languages for IronPython) 4. Hello Worldprint Hello World Hello Worlda=6print a; 6a=Helloa=a+ 6 Errors a=a + str(6) 5. *.py 6. Interpreter Output 7. Interpreter 8. Stringsa=Helloa=Helloa=I Cant do thisa=I Love Pythona=I Love PythonHelloHelloI Cant do thisI Love PythonI Love Python 9. a=Helloprint a[0]print len(a)print a[0:2]print a[2:]H5Hello 10. a=Helloprint a[-1]print a[-2:] olo 11. More About str Classprint dir(str) [__add__, __class__, __contains__, __delattr__, __doc__, __eq__, __ge__,__getattribute__, __getitem__, __getnewargs__, __getslice__, __gt__,__hash__, __init__, __le__, __len__, __lt__, __mod__, __mul__, __ne__,__new__, __reduce__, __reduce_ex__, __repr__, __rmod__, __rmul__,__setattr__, __str__, capitalize, center, count, decode, encode, endswith,expandtabs, find, index, isalnum, isalpha, isdigit, islower, isspace, istitle,isupper, join, ljust, lower, lstrip, partition, replace, rfind, rindex, rjust,rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title,translate, upper, zfill] 12. Help Classprint help(str.find)find(...) S.find(sub [,start [,end]]) -> intReturn the lowest index in S where substring sub is found,such that sub is contained within s[start,end]. Optionalarguments start and end are interpreted as in slice notation.Return -1 on failure. 13. Some Basic Syntax(1)n Oddn is Odd and greater than 5n divided by 2 or 5 14. Some Basic Syntax(1) //Array Declaration a=[]215Using Range:215True 15. List(1)a=[3,1,5]b=[4,2]c=a+bprint cdel c[2]print cprint len(c)[3,1,5,4,2][3,1,4,2]4 16. List(2)(a,b)=([3,1,5],[4,2])c=a+b c= sorted(c)print sorted(c)print a==bprint sorted(c,reverse=True)print cprint help(sorted)[1,2,3,4,5]False[5,4,3,2,1][3, 1, 5, 4, 2]Help on built-in function sorted in module __builtin__:sorted(...) sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list 17. List and Sorta=[ax,aae,aac] return 1,Hello Worlddef mFun(s): a,b=mFun(Hi)return s[-1]print sorted(a,key=mFun)print sorted(a,key=mFun,reverse=True)print sorted(a,key=len)[aac, aae, ax][ax, aae, aac][ax, aae, aac] 18. Tuplesa=(1,2,1)print a[0]print len(a)b=[(1,2,3),(1,2,1),(1,4,1)]print a in b13True 19. Tuples and sorta=[(1,"b"),(2,"a"),(1,"e")]print aprint sorted(a)def myTSort(d):return d[0]print sorted(a,key=myTSort)k=(1,e)print k in a[(1, b), (2, a), (1, e)][(1, b), (1, e), (2, a)][(2, a), (1, b), (1, e)]True 20. Dictionary d={} d[a]=alpha d[o]=omega d[g]=gamma print d[a]alpha 21. Dictionaryd={}(d[a],d[o],d[g])=("alpha","omega","gamma")print dprint len(d){a: alpha, g: gamma, o: omega}3Check a value is in dictionary ???a in d 22. Dictionaryd={}(d[a],d[o],d[g])=("alpha","omega","gamma")print d[a]print d[x] //???print d.get(x) // return Noneprint d.get(a) if(d.get(a)){print Yes } 23. Dictionaryd={}(d[a],d[o],d[g])=("alpha","omega","gamma")print d.keys()print d.values()print d.items()[a, g, o][alpha, gamma, omega][(a, alpha), (g, gamma), (o, omega)]What needs for sorted dictionary data(key order) ???All data returns random orderfor k in sorted( d.keys() ):print d[k]print sorted(d.keys()) 24. Dictionaryprint dir(dict)[__class__, __cmp__, __contains__, __delattr__, __delitem__,__doc__, __eq__, __ge__, __getattribute__, __getitem__, __gt__,__hash__, __init__, __iter__, __le__, __len__, __lt__, __ne__,__new__, __reduce__, __reduce_ex__, __repr__, __setattr__,__setitem__, __str__, clear, copy, fromkeys, get, has_key, items,iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update,values]print help(dict)print help(dict.items) 25. Filedef readFile(fileName): // File writef=open(fileName,r)f=open(fileName,w)f.write(data)for line in f:f.close() print line, f.close()def readFile(fileName):f=open(fileName,r)text=f.read()print textf.close() f.seek(5) 26. Regular expressionimport rematch=re.search(od,"God oder")print match.group()match=re.search(rod,"God oder")print match.group()odod 27. Regular expressionimport reprint re.findall(rar+,a ar arr)print re.findall(rar*,a ar arr)[ar, arr][a, ar, arr]+ for 1 or more* for 0 or moreprint dir(re) 28. Utility: OSimport osprint dir(os)[F_OK, O_APPEND, O_BINARY, O_CREAT, O_EXCL,O_NOINHERIT, O_RANDOM, O_RDONLY, O_RDWR,O_SEQUENTIAL, UserDict, W_OK, X_OK, _Environ, __all__,__builtins__, __doc__, __file__, __name__, _copy_reg,_pickle_statvfs_result, abort, access, altsep, chdir, chmod, close,curdir, defpath, isatty, linesep, listdir, lseek, lstat, makedirs, mkdir,name, open, pardir, path, pathsep, pipe, popen, popen2, popen3,popen4, putenv, read, remove, removedirs, rename, renames, rmdir,sep, spawnl, spawnle, spawnv, spawnve, startfile, stat,stat_float_times, stat_result, statvfs_result, strerror, sys, system,tempnam, times, tmpfile, tmpnam, umask, unlink, unsetenv,urandom, utime, waitpid, walk, write] 29. Utility: OSimport osprint help(os.unlink)unlink(...)unlink(path)Remove a file (same as remove(path)).print help(os.rmdir)rmdir(...)rmdir(path)Remove a directory. 30. Utility: HTTP request, URLtry:passexcept:passfinally:print ok 31. Some OOP class MyClass(AnotherClass): import myClass.py 32. Some OOP (Thread) 33. Access Shared Resource 34. Database(Sqlite) 35. Database(MySql) 36. Reserved Word and finally pass assert for print break from raise class global return continue if try def import while del in elif is else lambda except not exec or 37. Code Sourcehttp://jpython.blogspot.com/ 38. Resource http://www.learnpython.org/ http://learnpythonthehardway.org/book/ http://code.google.com/edu/languages/google- python-class/ http://love-python.blogspot.com http://jpython.blogspot.com 39. THANK YOU


Recommended