python assignment help
TRANSCRIPT
Python Tutorial Assignments• interactive "shell"• basic types: numbers, strings• container types: lists, dictionaries, tuples• variables• control structures• functions & procedures• classes & instances• modules & packages• exceptions• files & standard library• what's new in Python 2.0 and beyond
Python Assignment Overview
• Programs are composed of modules• Modules contain statements• Statements contain expressions• Expressions create and process objects
Python Assignment Interpreter
• >>> 3 + 7• 10• >>> 3 < 15 • True• >>> 'print me'• 'print me'• >>> print 'print me'• print me• >>>
• Python is an interpreted language
• The interpreter provides an interactive environment to play with the language
• Results of expressions are printed on the screen
Numbers: Integers
• Integer – the equivalent of a C long• Long Integer – an unbounded integer value.
Numbers: Floating Point
>>> 1.232321.2323200000000001>>> print 1.232321.23232>>> 1.3E713000000.0>>> int(2.0)2>>> float(2)2.0
int(x) converts x to an integerfloat(x) converts x to a floating pointThe interpreter shows a lot of digits
Running Interactively on UNIX
On Unix…% python>>> 3+36
• Python prompts with ‘>>>’. • To exit Python (not Idle):– In Unix, type CONTROL-D– In Windows, type CONTROL-Z + <Enter>– Evaluate exit()
Editing Python in Emacs• Emacs python-mode has good support for editing Python, enabled enabled by default
for .py files• Features: completion, symbol help, eldoc, and inferior interpreter shell, etc.
Basic Datatypes
• Integers (default for numbers)z = 5 / 2 # Answer 2, integer division
• Floatsx = 3.456
• Strings– Can use “” or ‘’ to specify with “abc” == ‘abc’– Unmatched can occur within the string: “matt’s”– Use triple double-quotes for multi-line strings or strings
than contain both ‘ and “ inside of them: “““a‘b“c”””
Python Assignment• Binding a variable in Python means setting a name to hold a
reference to some object– Assignment creates references, not copies
• Names in Python do not have an intrinsic type, objects have types– Python determines the type of the reference automatically based on
what data is assigned to it• You create a name the first time it appears on the left side of an
assignment expression: x = 3
• A reference is deleted via garbage collection after any names bound to it have passed out of scope
• Python uses reference semantics (more later)
Python Features• no compiling or linking• rapid development cycle• no type declarations• simpler, shorter, more flexible• automatic memory management• garbage collection• high-level data types and operations• fast development• object-oriented programming• code structuring and reuse, C++• embedding and extending in C• mixed language systems• classes, modules, exceptions• "programming-in-the-large" support• dynamic loading of C modules• simplified extensions, smaller binaries• dynamic reloading of C modules• programs can be modified without stopping
Python structure
• modules: Python source files or C extensions– import, top-level via from, reload
• statements– control flow– create objects– indentation matters – instead of {}
• objects– everything is an object– automatically reclaimed when no longer needed
Language comparisonTcl Perl Pytho
nJavaScript
Visual Basic
Speed development regexp
breadth extensible embeddable easy GUI (Tk) net/web
enterprise
cross-platform
I18N thread-safe database access