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 an...
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()
>>> prin...
Global and local Variables in Functions
>>>
...
...
>>>
>>>
>>>

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

def f():
print s
s = "Me too."
print s
s = "I hate sp...
Global and local Variables in Functions
>>> def f():
... print s
... s = "Me too."
... print s
>>> s = "I hate spam."
>>> ...
Global and local Variables in Functions
>>> def f():
... global s
... print s
... s = "That's clear."
... print s
>>> s = ...
Global and local Variables in Functions
>>> def f():
... global s
... print s
... s = "That's clear."
... print s
>>> s = ...
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 a...
References
SPSE securitytube training by Vivek Ramachandran
SANS Python for Pentesters (SEC573)
Violent python
Security Po...
This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License.
To view a copy of this license...
Upcoming SlideShare
Loading in …5
×

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

222 views
166 views

Published on

در این جلسه به بحث
Namespace
Local and Global variables
پرداختیم
PySec101 Fall 2013 J6E2 By Mohammad Reza Kamalifard
Talk About:
Namespace and Local,Global variables in Python

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
222
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

  1. 1. Python for ethical hackers Mohammad reza Kamalifard kamalifard@datasec.ir
  2. 2. Python language essentials Module 1: Introduction to Python and Setting up an Environment for Programing Part 8: Global and Local Variables
  3. 3. Global and local Variables in Functions >>> def f(): ... print s >>> s = "I hate spam" >>> f()
  4. 4. Global and local Variables in Functions >>> def f(): ... print s >>> s = "I hate spam" >>> f() i hate spam >>>
  5. 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. 6. Global and local Variables in Functions >>> ... ... >>> >>> >>> def f(): s = "Me too." print s s = "I hate spam." f() print s
  7. 7. Global and local Variables in Functions >>> ... ... ... >>> >>> >>> def f(): print s s = "Me too." print s s = "I hate spam." f() print s
  8. 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. 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. 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. 11. Global and local Variables in Functions >>> def f(): ... s = "I am globally not known" ... print s >>> f() >>> print s
  12. 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. 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. 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 .

×