در این جلسه به بحث
Namespace
Local and Global variables
پرداختیم
PySec101 Fall 2013 J6E2 By Mohammad Reza Kamalifard
Talk About:
Namespace and Local,Global variables in Python
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
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 .