1 / 121

>>> print 'Hello, World!'

>>> print 'Hello, World!'. Hello, World!. >>>. >>> print 'Welcome to PYSEC101 Course'. Welcome to PYSEC101 Course. >>>. >>> 'Hello World'. 'Hello World'. >>> 3. 3. >>>. >>> 12 / 7. 1. >>>. >>> 12.0 / 7. 1.7142857142857142. >>>. >>> float ( 12 ) / 7.

walter
Download Presentation

>>> print 'Hello, World!'

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. >>> print 'Hello, World!' Hello, World! >>> >>> print 'Welcome to PYSEC101 Course' Welcome to PYSEC101 Course >>> >>> 'Hello World' 'Hello World' >>> 3 3 >>>

  2. >>> 12 / 7 1 >>> >>> 12.0 / 7 1.7142857142857142 >>> >>> float(12) / 7 1.7142857142857142 >>>

  3. >>> 3 + 2 * 4 11 >>> ( 3 + 2 ) * 4 20 >>> >>> _ 20 >>>

  4. • • •

  5. $ vim Hello.py print 'Hello, World!' ~ ~ ~ ~ ~ ~ ~ $ python Hello.py Hello, World!

  6. • • • •

  7. • • •

  8. >>> name = 'reza' >>> print name reza >>> >>>name = 10 >>>name 10

  9. >>> name = 10 >>> type (name) <type 'int'> >>> name = 'Reza' >>> type (name) <type 'str'> >>> name = 10.42 >>> type (name) <type 'float'> >>>

  10. • • •

  11. • • • •

  12. >>> name = 'reza' >>> id(name) 3072831328L >>> hex(id(name)) '0xb727af60L' >>> >>> name.__repr__ <method-wrapper '__repr__' of str object at 0xb727af60> >>> 0xb727af60

  13. • • >>> a = 010 >>> print a 8 • >>> hex_number = 0xA0F >>> print hex_number 2575 • •

  14. >>>int('10') 10 >>>int('0011', 2) 3 >>>int('1111', 2) 15 >>>int('0xff', 16) 255

  15. • • •

  16. >>>name = 'reza' >>>name = reza >>>name = rez'a >>>name = 'Mohammd\nreza' >>>print name Mohammad reza

  17. >>>name = r'Mohammd\nreza' print name Mohammd\nreza >>>

  18. >>> name = ''' ... Hello Dear Students ... Welcome to PYSEC101 Course! ... Python Scripting Course for Ethical Hackers ... ''' >>> name '\nHello Dear Students\nWelcome to PYSEC101 Course!\nPython Scripting Course for Ethical Hackers\n' >>> print name Hello Dear Students Welcome to PYSEC101 Course! Python Scripting Course for Ethical Hackers

  19. •

  20. • • >>>name = u'Mohammad' >>> name u'Mohammad' >>> >>> str(name) 'Mohammad' >>> >>> unicode(name) u'Mohammad' >>>

  21. • >>>s1 + s2 >>> s1 = 'Hamid' >>> s2 = 'rezaie' >>> s1 + s2 'Hamidrezaie' >>> s1 + ' ' + s2 'Hamid rezaie' >>>

  22. • >>> buffer = 'A' * 20 >>> buffer 'AAAAAAAAAAAAAAAAAAAA' >>>

  23. • • • • • • • •

  24. • • •

  25. >>> name = 'Mohammad reza' >>> name[5:10] 'mad r' >>> name[0:10] 'Mohammad r' >>> name[0:-1] 'Mohammad rez' >>> name[0:-5] 'Mohammad' >>> name[:] 'Mohammad reza' >>> name[::-1] 'azer dammahoM' >>> name[::2] 'Mhma ea' >>>

  26. >>>name = 'reza' >>>name[ 0] r name [0 ] = 'a' TypeError: 'str' object does not support item assignment You can not change String Object directly in memory because they are immutable >>>name = 'reza' name = 'Mohammad' •

  27. • • •

  28. >>> name = 'mohammad reza' >>> name.find('PYSEC101') -1 >>> name.find('mma') 4 >>> >>> name.split() ['mohammad', 'reza'] >>> name.split('a') ['moh', 'mm', 'd rez', ''] >>> >>> name.replace('m', 'H') 'HohaHHad reza' >>>

  29. >>> ip = '192.168.1.252' >>> line = 'Crack this IP : %s' % ip >>> line 'Crack this IP :192.168.1.252' >>> >>> line = 'Crack this IP : %s and name %s ' % (ip, 'Reza-PC') >>> line 'Crack this IP : 192.168.1.252 and name Reza-PC '

  30. • • >>> my_list = ['English', 'Farsi', 'Arabic', 'German',] >>> my_list[0] 'English' >>> my_list[1] 'Farsi' >>> my_list[-1] 'German' >>> my_list[2:3] ['Arabic'] >>> my_list[::-1] ['German', 'Arabic', 'Farsi', 'English']

  31. my_list = [1,2,3,4] my_list= [1, 'reza', 'PYSEC101', 2.5] >>>my_list= [1, [3,4, 'Hello'], [3,4], 2, 3] >>>len(my_list) 5 >>>len(my_list[1]) 3 >>>

  32. • • • • • • •

  33. >>> my_list1 = [1, 2] >>> my_list2 = [3, 4] >>> my_list = my_list1 + my_list2 >>> my_list [1, 2, 3, 4] >>> my_list.append(5) >>> my_list [1, 2, 3, 4, 5] >>> my_list.append([6, 7]) >>> my_list [1, 2, 3, 4, 5, [6, 7]] >>> my_list.extend([8, 9]) >>> my_list [1, 2, 3, 4, 5, [6, 7], 8, 9] >>>

  34. >>> my_list [1, 2, 3, 4, 5, [6, 7], 8, 9] >>> my_list.pop() 9 >>> my_list [1, 2, 3, 4, 5, [6, 7], 8] >>> my_list.insert(2, 12) >>> my_list [1, 2, 12, 3, 4, 5, [6, 7], 8] >>> del my_list[2] >>> my_list [1, 2, 3, 4, 5, [6, 7], 8] >>>

  35. • • • • >>>my_tuple = ('reza', 1362, 22, 'aban') >>>my_tuple ('reza', 1362, 22, 'aban') >>> my_tuple[2] 22 >>> my_tuple[2] = 14 Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> my_tuple[2] = 14 TypeError: 'tuple' object does not support item assignment >>>

  36. >>> post_data = tuple(['PYSEC101', 25, 100, 3]) >>> post_data ('PYSEC101', 25, 100, 3) >>> sequence unpacking >>> post_name, view, comments, upvotes = post_data >>> post_name 'PYSEC101' >>> >>> view 25 >>> comments 100 >>> upvotes 3

  37. • • • • • • •

  38. >>> set1 = set([1 , 2, 3, 3, 2]) >>> set1 set([1, 2, 3]) >>> >>> set2 = set(['Hamid', 'Ali', 'Reza' , 'Hamid', 'Reza', 2, 5, 2, 1, 3, 5]) >>> set2 set([1, 2, 3, 5, 'Ali', 'Reza', 'Hamid']) >>> >>> set3 = set([3 , 4, 5]) >>> set3 set([3, 4, 5])

  39. Sets >>> set1 | set3 set([1, 2, 3, 4, 5]) >>> >>> set1 & set3 set([3]) >>> >>> set1 - set3 set([1, 2]) >>> >>> set3 - set1 set([4, 5])

  40. Dictionaries • Unordered key-value pairs • Keys are unique and immutable objects • Value can change • Check if a given key is present • dict.has_keyUnordered key-value pairs • Keys are unique and immutable objects • Value can change • Check if a given key is present • dict.has_keyy(key • keyindict { 'key' : 'value' } >>>my_dic1 = {} >>>my_dic1['name'] = 'reza' {'name': 'reza'} >>> my_dic2 = {'name' : 'reza', 'age' : 23} >>> my_dic2 {'age': 23, 'name': 'reza'}

  41. >>> user = {'name': 'reza', 'age': 23, 'from': 'Iran'} >>> user {'age': 23, 'from': 'Iran', 'name': 'reza'} >>> >>> user.has_key('name') True >>> user.has_key('hobby') False >>> 'name' in user True >>> 'Iran' in user False

  42. • • • • • • •

  43. Dictionaries >>> user.keys() ['age', 'from', 'name'] >>> user.values() [23, 'Iran', 'reza'] >>> user.items () [('age', 23), ('from', 'Iran'), ('name', 'reza')] >>> >>> user.get('age' ) 23 >>> user['age'] 23

  44. Add new Value >>> user['Fav_Site'] = 'Twitter.com' >>> user {'age': 23, 'from': 'Iran', 'name': 'reza', 'Fav_Site': 'Twitter.com'} >>> Delete an item >>> del user['Fav_Site'] >>> user {'age': 23, 'from': 'Iran', 'name': 'reza'} >>> >>> user.clear() >>> user {}

  45. Help • • •

  46. () >>> name = 'reza' >>> dir(name) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', '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'] >>>

  47. () • •

More Related