Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

در این جلسه به بحث
Name Space
Local and Global variables
پرداختیم

Mohammad reza Kamalifard

November 18, 2013
Tweet

More Decks by Mohammad reza Kamalifard

Other Decks in Education

Transcript

  1. Python language essentials Module 1: Introduction to Python and Setting

    up an Environment for Programing Part 8: Global and Local Variables
  2. Global and local Variables in Functions >>> def f(): ...

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

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

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

    print s ... 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 UnboundLocalError: local variable 's' referenced before assignment
  8. 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
  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 Python is great! That's clear. That's clear.
  10. Global and local Variables in Functions >>> def f(): ...

    s = "I am globally not known" ... print s >>> f() >>> print s
  11. 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
  12. 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
  13. 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 .