Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented.

Similar presentations


Presentation on theme: "Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented."— Presentation transcript:

1 Python By Steve Wright

2 What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented Interpreted Interpreted Procedural Procedural Open source Open source Interactive Interactive Dynamic typing Dynamic typing Garbage collection Garbage collection

3 Brief History Written by Guido van Rossum; Dec. 1989 Written by Guido van Rossum; Dec. 1989 Descendant of ABC Descendant of ABC Used for system administration (Amoeba) Used for system administration (Amoeba) Appeal to UNIX/C developers Appeal to UNIX/C developers Python Software Activity (PSA) Python Software Activity (PSA) www.python.org www.python.org

4 Basic structure 1. Programs are composed of modules 2. Modules contain statements 3. Statements create and process objects Modules can be imported and used in interactive mode (like Scheme) Modules can be imported and used in interactive mode (like Scheme) Uses indentation to create blocks and scope Uses indentation to create blocks and scope

5 Basic Types Numbers – ints, long ints (unlimited size), floating-point, octal/hex, complex Numbers – ints, long ints (unlimited size), floating-point, octal/hex, complex Operators: +, -, /, *, >>, **, etc. Operators: +, -, /, *, >>, **, etc. Strings – ordered collection of characters Strings – ordered collection of characters Operators: +, *, [i:j], len, for x in y, etc. Operators: +, *, [i:j], len, for x in y, etc. Lists – ordered collection of objects Lists – ordered collection of objects Operators: similar to String operators Operators: similar to String operators Dictionaries – hash tables Dictionaries – hash tables Operators: has_key, keys, values, len, etc. Operators: has_key, keys, values, len, etc.

6 List sample L = [0, 1, 2] create a list of 3 items L = [0, 1, 2] create a list of 3 items L.append(-3) add element to end L.append(-3) add element to end L.insert(3, 50) insert 50 at index 3 L.insert(3, 50) insert 50 at index 3 L.sort() sort the list L.sort() sort the list del L[4:5] delete a slice of list del L[4:5] delete a slice of list L.reverse() reverse the list L.reverse() reverse the list

7 Program example items = [“aaa”, 111, (4, 5), 2.01] tests = [(4, 5), 3.14]# items to search for for key in tests: if key in items: if key in items: print key, “was found” else: else: print key, “not found” (4, 5) was found 3.14 not found

8 Advantages Dynamic typing – doesn’t require complicated type and size declarations Dynamic typing – doesn’t require complicated type and size declarations Built-in objects and tools to use them Built-in objects and tools to use them Vast library utilities – system, networking, regular expressions, etc. Vast library utilities – system, networking, regular expressions, etc. Automatic memory management Automatic memory management Comes with standard GUI API (Tkinter) Comes with standard GUI API (Tkinter) Rapid prototype tool for C programs Rapid prototype tool for C programs Simple, easy to read/learn, and it’s free! Simple, easy to read/learn, and it’s free!

9 Disadvantages Slower and less efficient than static, compiled languages like C Slower and less efficient than static, compiled languages like C Device drivers and other OS kernal programs are not suitable for Python because of it’s dynamic memory allocation Device drivers and other OS kernal programs are not suitable for Python because of it’s dynamic memory allocation


Download ppt "Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented."

Similar presentations


Ads by Google