SlideShare a Scribd company logo
Python for ethical hackers
Mohammad reza Kamalifard
kamalifard@datasec.ir
Python language essentials
Module 1:
Introduction to Python and Setting up an Environment for Programing
Part 3 :
Lists,Tuple, Sets, Dictionaries
Lists
• Collection of objects which can be heterogeneous
• Lists are like Arrays in C/C++ and Java, but Python lists are by far

more flexible than classical arrays.
>>> 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']
Lists
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
>>>
List Operations
• Concatenate [1,2] + [3,4] = [1,2,3,4]
• Append – list.append()
• Extend – list.extend()
• Reverse – list.reverse()
• Pop – list.pop()
• Insert – list.insert(index,item)
• Delete – del list[index]
>>>
>>>
>>>
>>>
[1,
>>>
>>>
[1,
>>>
>>>
[1,
>>>
>>>
[1,
>>>

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

my_list
2, 3, 4, 5, [6, 7], 8, 9]
my_list.pop()
my_list
2, 3, 4, 5, [6, 7], 8]
my_list.insert(2, 12)
my_list
2, 12, 3, 4, 5, [6, 7], 8]
del my_list[2]
my_list
2, 3, 4, 5, [6, 7], 8]
Tuples
• Tuples are similar to list but immutable
• Can Convert from list to tuple and vice versa
• tuple(list)
• list(tuple)

>>>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
>>>
>>> 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
Sets
• Unordered collection of unique objects
• List to set : b = set(a)
• Set to list : a = list(b)
• Set Operations
• Union: a | b
• Intersection: a & b
• Difference: a - b
Sets
>>> set1 =
>>> set1
set([1, 2,
>>>
>>> set2 =
'Reza', 2,
>>> set2
set([1, 2,
>>>
>>> set3 =
>>> set3
set([3, 4,

set([1, 2, 3, 3, 2])
3])
set(['Hamid', 'Ali', 'Reza', 'Hamid',
5, 2, 1, 3, 5])
3, 5, 'Ali', 'Reza', 'Hamid'])
set([3, 4, 5])
5])
Sets
>>> set1 | set3
set([1, 2, 3, 4, 5])
>>>
>>> set1 & set3
set([3])
>>>
>>> set1 - set3
set([1, 2])
>>>
>>> set3 - set1
set([4, 5])
Dictionaries
• Unordered key-value pairs
• Keys are unique and immutable objects
• Value can change
• Check if a given key is present
• dict.has_key(key)
• key in dict

{ 'key' : 'value' }
>>>my_dic1 = {}
>>>my_dic1['name'] = 'reza'
{'name': 'reza'}
>>> my_dic2 = {'name' : 'reza', 'age' : 23}
>>> my_dic2
{'age': 23, 'name': 'reza'}
Dictionaries
>>> 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
Dictionaries
• Get tuple of items : dict.items()
• Get list of keys : dict.keys()
• Get list of values : dict.values()
• Get a particular item : dict.get(key)
• Item deletion:
• All item : dict.clear()
• one item: del dict[key]
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
Dictionaries
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
{}
Getting Help
• Getting Help on Methods and etc.
• dir() : lists all attributes
• help(string.replace) – list method help
dir()
>>> 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']
>>>
help()
• Help on built-in function replace:
• help(name.replace)
replace(...)
S.replace(old, new[, count]) -> string
Return a copy of string S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
(END)
References
SPSE securitytube training by Vivek Ramachandran
SANS Python for Pentesters (SEC573)
Violent python
Security Power Tools
python-course.eu
----------------------------http://www.tutorialspoint.com/python/python_lists.htm
http://www.tutorialspoint.com/python/python_tuples.htm
http://www.tutorialspoint.com/python/python_dictionary.htm
http://www.python-course.eu/sequential_data_types.php
http://www.python-course.eu/sets_frozensets.php
This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nd/3.0/
Copyright 2013 Mohammad Reza Kamalifard
All rights reserved.
Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .

More Related Content

PPTX
python chapter 1
PPTX
Python chapter 2
PDF
PyLecture4 -Python Basics2-
PPTX
Python data structures
PDF
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PDF
Codigos
PDF
Clustering com numpy e cython
PDF
Palestra sobre Collections com Python
python chapter 1
Python chapter 2
PyLecture4 -Python Basics2-
Python data structures
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Codigos
Clustering com numpy e cython
Palestra sobre Collections com Python

What's hot (16)

PPTX
Ruby's Arrays and Hashes with examples
PDF
Being Google
ODP
Very basic functional design patterns
PDF
Python lists
PDF
Python Usage (5-minute-summary)
PDF
Pre-Bootcamp introduction to Elixir
PDF
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PPTX
Ruby Language: Array, Hash and Iterators
RTF
Seistech SQL code
PPTX
R part iii
PDF
Parse Everything With Elixir
PDF
The Magic Of Elixir
PDF
Elixir & Phoenix – fast, concurrent and explicit
PDF
Elixir & Phoenix – fast, concurrent and explicit
PDF
[1062BPY12001] Data analysis with R / week 4
PDF
Python an-intro youtube-livestream-day2
Ruby's Arrays and Hashes with examples
Being Google
Very basic functional design patterns
Python lists
Python Usage (5-minute-summary)
Pre-Bootcamp introduction to Elixir
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
Ruby Language: Array, Hash and Iterators
Seistech SQL code
R part iii
Parse Everything With Elixir
The Magic Of Elixir
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
[1062BPY12001] Data analysis with R / week 4
Python an-intro youtube-livestream-day2
Ad

Viewers also liked (6)

PDF
Pycon - Python for ethical hackers
PDF
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
PDF
PDF
Introduction to Flask Micro Framework
PDF
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Pycon - Python for ethical hackers
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
Introduction to Flask Micro Framework
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Ad

Similar to جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲ (20)

PDF
اسلاید اول جلسه چهارم کلاس پایتون برای هکرهای قانونی
PPTX
Python introduction data structures lists etc
PPT
Tuples, sets and dictionaries-Programming in Python
PPTX
Datastructures in python
PPTX
Chapter 3-Data structure in python programming.pptx
PPTX
Python data structures
PPTX
Seventh session
PPT
Tuples, sets angsdfgsfdgdfgfdgd dictionaries 2.ppt
PPTX
python advanced data structure dictionary with examples python advanced data ...
PPTX
Python Lecture 11
DOC
Revision Tour 1 and 2 complete.doc
PPTX
Dictionaries and Sets
PDF
Programming in python Unit-1 Part-1
PPTX
UNIT-4.pptx python for engineering students
PPTX
Python list tuple dictionary .pptx
PPTX
Intro Python Data Structures.pptx Intro Python Data Structures.pptx
PPTX
datastrubsbwbwbbwcturesinpython-3-4.pptx
PPTX
Python lec2
PPTX
Data Type In Python.pptx
PDF
Python Variable Types, List, Tuple, Dictionary
اسلاید اول جلسه چهارم کلاس پایتون برای هکرهای قانونی
Python introduction data structures lists etc
Tuples, sets and dictionaries-Programming in Python
Datastructures in python
Chapter 3-Data structure in python programming.pptx
Python data structures
Seventh session
Tuples, sets angsdfgsfdgdfgfdgd dictionaries 2.ppt
python advanced data structure dictionary with examples python advanced data ...
Python Lecture 11
Revision Tour 1 and 2 complete.doc
Dictionaries and Sets
Programming in python Unit-1 Part-1
UNIT-4.pptx python for engineering students
Python list tuple dictionary .pptx
Intro Python Data Structures.pptx Intro Python Data Structures.pptx
datastrubsbwbwbbwcturesinpython-3-4.pptx
Python lec2
Data Type In Python.pptx
Python Variable Types, List, Tuple, Dictionary

More from Mohammad Reza Kamalifard (20)

PDF
جلسه چهارم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
PDF
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
PDF
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
PDF
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
PDF
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PDF
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید اول جلسه پنجم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه چهارم کلاس پایتون برای هکرهای قانونی
جلسه چهارم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه چهارم کلاس پایتون برای هکرهای قانونی

Recently uploaded (20)

PDF
Yogi Goddess Pres Conference Studio Updates
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Updated Idioms and Phrasal Verbs in English subject
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Computing-Curriculum for Schools in Ghana
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Yogi Goddess Pres Conference Studio Updates
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial diseases, their pathogenesis and prophylaxis
Supply Chain Operations Speaking Notes -ICLT Program
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Updated Idioms and Phrasal Verbs in English subject
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Computing-Curriculum for Schools in Ghana
Weekly quiz Compilation Jan -July 25.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Microbial disease of the cardiovascular and lymphatic systems
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
A systematic review of self-coping strategies used by university students to ...
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲

  • 1. Python for ethical hackers Mohammad reza Kamalifard kamalifard@datasec.ir
  • 2. Python language essentials Module 1: Introduction to Python and Setting up an Environment for Programing Part 3 : Lists,Tuple, Sets, Dictionaries
  • 3. Lists • Collection of objects which can be heterogeneous • Lists are like Arrays in C/C++ and Java, but Python lists are by far more flexible than classical arrays. >>> 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']
  • 4. Lists 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 >>>
  • 5. List Operations • Concatenate [1,2] + [3,4] = [1,2,3,4] • Append – list.append() • Extend – list.extend() • Reverse – list.reverse() • Pop – list.pop() • Insert – list.insert(index,item) • Delete – del list[index]
  • 6. >>> >>> >>> >>> [1, >>> >>> [1, >>> >>> [1, >>> >>> [1, >>> my_list1 = [1, 2] my_list2 = [3, 4] my_list = my_list1 + my_list2 my_list 2, 3, 4] my_list.append(5) my_list 2, 3, 4, 5] my_list.append([6, 7]) my_list 2, 3, 4, 5, [6, 7]] my_list.extend([8, 9]) my_list 2, 3, 4, 5, [6, 7], 8, 9]
  • 7. >>> [1, >>> 9 >>> [1, >>> >>> [1, >>> >>> [1, >>> my_list 2, 3, 4, 5, [6, 7], 8, 9] my_list.pop() my_list 2, 3, 4, 5, [6, 7], 8] my_list.insert(2, 12) my_list 2, 12, 3, 4, 5, [6, 7], 8] del my_list[2] my_list 2, 3, 4, 5, [6, 7], 8]
  • 8. Tuples • Tuples are similar to list but immutable • Can Convert from list to tuple and vice versa • tuple(list) • list(tuple) >>>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 >>>
  • 9. >>> 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
  • 10. Sets • Unordered collection of unique objects • List to set : b = set(a) • Set to list : a = list(b) • Set Operations • Union: a | b • Intersection: a & b • Difference: a - b
  • 11. Sets >>> set1 = >>> set1 set([1, 2, >>> >>> set2 = 'Reza', 2, >>> set2 set([1, 2, >>> >>> set3 = >>> set3 set([3, 4, set([1, 2, 3, 3, 2]) 3]) set(['Hamid', 'Ali', 'Reza', 'Hamid', 5, 2, 1, 3, 5]) 3, 5, 'Ali', 'Reza', 'Hamid']) set([3, 4, 5]) 5])
  • 12. Sets >>> set1 | set3 set([1, 2, 3, 4, 5]) >>> >>> set1 & set3 set([3]) >>> >>> set1 - set3 set([1, 2]) >>> >>> set3 - set1 set([4, 5])
  • 13. Dictionaries • Unordered key-value pairs • Keys are unique and immutable objects • Value can change • Check if a given key is present • dict.has_key(key) • key in dict { 'key' : 'value' } >>>my_dic1 = {} >>>my_dic1['name'] = 'reza' {'name': 'reza'} >>> my_dic2 = {'name' : 'reza', 'age' : 23} >>> my_dic2 {'age': 23, 'name': 'reza'}
  • 14. Dictionaries >>> 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
  • 15. Dictionaries • Get tuple of items : dict.items() • Get list of keys : dict.keys() • Get list of values : dict.values() • Get a particular item : dict.get(key) • Item deletion: • All item : dict.clear() • one item: del dict[key]
  • 16. 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
  • 17. Dictionaries 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 {}
  • 18. Getting Help • Getting Help on Methods and etc. • dir() : lists all attributes • help(string.replace) – list method help
  • 19. dir() >>> 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'] >>>
  • 20. help() • Help on built-in function replace: • help(name.replace) replace(...) S.replace(old, new[, count]) -> string Return a copy of string S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced. (END)
  • 21. References SPSE securitytube training by Vivek Ramachandran SANS Python for Pentesters (SEC573) Violent python Security Power Tools python-course.eu ----------------------------http://www.tutorialspoint.com/python/python_lists.htm http://www.tutorialspoint.com/python/python_tuples.htm http://www.tutorialspoint.com/python/python_dictionary.htm http://www.python-course.eu/sequential_data_types.php http://www.python-course.eu/sets_frozensets.php
  • 22. This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/ Copyright 2013 Mohammad Reza Kamalifard All rights reserved. Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .