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 8:
Global and Local Variables
Global and local Variables in Functions
>>> def f():
... print s
>>> s = "I hate spam"
>>> f()
Global and local Variables in Functions
>>> def f():
... print s
>>> s = "I hate spam"
>>> f()
i hate spam
>>>
Global and local Variables in Functions
>>> def f():
... s = "Me too."
... print s
>>> s = "I hate spam."
>>> f()
>>> print s
Me too.
I hate spam.
Global and local Variables in Functions
>>>
...
...
>>>
>>>
>>>

def f():
s = "Me too."
print s
s = "I hate spam."
f()
print s
Global and local Variables in Functions
>>>
...
...
...
>>>
>>>
>>>

def f():
print s
s = "Me too."
print s
s = "I hate spam."
f()
print s
Global and local Variables in Functions
>>> def f():
... print s
... s = "Me too."
... print s
>>> s = "I hate spam."
>>> f()
>>> print s
UnboundLocalError: local variable 's' referenced
before assignment
Global and local Variables in Functions
>>> def f():
... global s
... print s
... s = "That's clear."
... print s
>>> s = "Python is great!"
>>> f()
>>> print s
Global and local Variables in Functions
>>> def f():
... global s
... print s
... s = "That's clear."
... print s
>>> s = "Python is great!"
>>> f()
>>> print s
Python is great!
That's clear.
That's clear.
Global and local Variables in Functions
>>> def f():
... s = "I am globally not known"
... print s
>>> f()
>>> print s
Global and local Variables in Functions
>>> def f():
... s = "I am globally not known"
... print s
>>> f()
>>> print s
I am globally not known
Traceback (most recent call last):
File "global_local3.py", line 6, in <module>
print s
NameError: name 's' is not defined
References
SPSE securitytube training by Vivek Ramachandran
SANS Python for Pentesters (SEC573)
Violent python
Security Power Tools
python-course.eu
----------------------------http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
http://www.python-course.eu/global_vs_local_variables.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

TXT
Popstat1 sh
TXT
Pop3stat sh
PDF
Python Workshop by Tom Frantz
PPTX
5 Time Saving Bash Tricks
PDF
PPT
01 linux basics
PDF
Go, the one language to learn in 2014
PDF
Popstat1 sh
Pop3stat sh
Python Workshop by Tom Frantz
5 Time Saving Bash Tricks
01 linux basics
Go, the one language to learn in 2014

What's hot (13)

ODT
Pendrive formatting
PPTX
Scripting 101
ODP
Linux Command Line
PDF
How not to delete your important files
PPTX
Build a compiler in 2hrs - NCrafts Paris 2015
KEY
Python 3.3 チラ見
PPTX
Code tacoma command_line
PPT
Unix And C
PPTX
Using the Power to Prove
PDF
Beware sharp tools
PPT
Basic command ppt
PDF
A toolbelt of seasoned bug hunter - Damir Zekic
PPTX
PHP Filing
Pendrive formatting
Scripting 101
Linux Command Line
How not to delete your important files
Build a compiler in 2hrs - NCrafts Paris 2015
Python 3.3 チラ見
Code tacoma command_line
Unix And C
Using the Power to Prove
Beware sharp tools
Basic command ppt
A toolbelt of seasoned bug hunter - Damir Zekic
PHP Filing
Ad

Viewers also liked (7)

PPTX
Jabatan kemajuan islam malaysia
PPTX
Komunikasi organisasi
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PDF
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PPTX
Dr zaghloul al najjar
PPTX
Dr zaghloul al najjar
PPTX
Dr zaghloul al najjar
Jabatan kemajuan islam malaysia
Komunikasi organisasi
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Dr zaghloul al najjar
Dr zaghloul al najjar
Dr zaghloul al najjar
Ad

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

PPTX
Chapter 3 Using Unix Commands
PDF
Python - File operations & Data parsing
PPTX
2 Functions2.pptx
PDF
Ruby - Uma Introdução
PDF
Funkcija, objekt, python
PDF
KEY
Desarrollando aplicaciones web en minutos
PPTX
Functions2.pptx
PPT
Computer 10 Quarter 3 Lesson .ppt
PPT
Unix And Shell Scripting
PDF
Using browser() in R
PPTX
Pythonppt28 11-18
PPTX
FUNDAMENTALS OF PYTHON LANGUAGE
PDF
PythonOOP
PPT
01_linux_basics tutorial for install.ppt
PPT
10.8.2018
PPT
01_linux_basics.ppt
PPTX
GE8151 Problem Solving and Python Programming
PDF
cel shading as PDF and Python description
Chapter 3 Using Unix Commands
Python - File operations & Data parsing
2 Functions2.pptx
Ruby - Uma Introdução
Funkcija, objekt, python
Desarrollando aplicaciones web en minutos
Functions2.pptx
Computer 10 Quarter 3 Lesson .ppt
Unix And Shell Scripting
Using browser() in R
Pythonppt28 11-18
FUNDAMENTALS OF PYTHON LANGUAGE
PythonOOP
01_linux_basics tutorial for install.ppt
10.8.2018
01_linux_basics.ppt
GE8151 Problem Solving and Python Programming
cel shading as PDF and Python description

More from Mohammad Reza Kamalifard (20)

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

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Insiders guide to clinical Medicine.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Complications of Minimal Access Surgery at WLH
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial diseases, their pathogenesis and prophylaxis
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Types and Its function , kingdom of life
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
VCE English Exam - Section C Student Revision Booklet
Supply Chain Operations Speaking Notes -ICLT Program
Insiders guide to clinical Medicine.pdf
human mycosis Human fungal infections are called human mycosis..pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Pre independence Education in Inndia.pdf
O7-L3 Supply Chain Operations - ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
Basic Mud Logging Guide for educational purpose
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Week 4 Term 3 Study Techniques revisited.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Module 4: Burden of Disease Tutorial Slides S2 2025

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

  • 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 8: Global and Local Variables
  • 3. Global and local Variables in Functions >>> def f(): ... print s >>> s = "I hate spam" >>> f()
  • 4. Global and local Variables in Functions >>> def f(): ... print s >>> s = "I hate spam" >>> f() i hate spam >>>
  • 5. Global and local Variables in Functions >>> def f(): ... s = "Me too." ... print s >>> s = "I hate spam." >>> f() >>> print s Me too. I hate spam.
  • 6. Global and local Variables in Functions >>> ... ... >>> >>> >>> def f(): s = "Me too." print s s = "I hate spam." f() print s
  • 7. Global and local Variables in Functions >>> ... ... ... >>> >>> >>> def f(): print s s = "Me too." print s s = "I hate spam." f() print s
  • 8. Global and local Variables in Functions >>> def f(): ... print s ... s = "Me too." ... print s >>> s = "I hate spam." >>> f() >>> print s UnboundLocalError: local variable 's' referenced before assignment
  • 9. Global and local Variables in Functions >>> def f(): ... global s ... print s ... s = "That's clear." ... print s >>> s = "Python is great!" >>> f() >>> print s
  • 10. Global and local Variables in Functions >>> def f(): ... global s ... print s ... s = "That's clear." ... print s >>> s = "Python is great!" >>> f() >>> print s Python is great! That's clear. That's clear.
  • 11. Global and local Variables in Functions >>> def f(): ... s = "I am globally not known" ... print s >>> f() >>> print s
  • 12. Global and local Variables in Functions >>> def f(): ... s = "I am globally not known" ... print s >>> f() >>> print s I am globally not known Traceback (most recent call last): File "global_local3.py", line 6, in <module> print s NameError: name 's' is not defined
  • 13. References SPSE securitytube training by Vivek Ramachandran SANS Python for Pentesters (SEC573) Violent python Security Power Tools python-course.eu ----------------------------http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ http://www.python-course.eu/global_vs_local_variables.php
  • 14. 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 .