Basics of python programming ppt

python programming language tutorial ppt and python programming an introduction to computer science ppt
Prof.WilliamsHibbs Profile Pic
Prof.WilliamsHibbs,United States,Teacher
Published Date:28-07-2017
Your Website URL(Optional)
Introduction to Python An introduction to Python programming with NumPy, SciPy and Matplotlib/Pylab Antoine Lefebvre Sound Modeling, Acoustics and Signal Processing Research AxisIntroduction to Python Introduction Introduction I Python is a simple, powerful and ecient interpreted language. I Together with the NumPy, SciPy and Matplotlib/Pylab, it provides a nice environment for scienti c works. I It is a good alternative to Matlab. It does not provide as much functionality, but the language is way more powerful. I Some programming experience (C/C++ and/or Matlab) would help to follow the workshop.Introduction to Python Introduction Goals of the presentation I Introduce the Python programming language and standard libraries. I Introduce the Numpy, Scipy and Matplotlib/Pylab packages. I Discuss how it can be useful for CIRMMT members.Introduction to Python Introduction content of the presentation I Python - description of the language I Language I Syntax I Types I Conditionals and loops I Errors I Functions I Modules I Classes I Python - overview of the standard library I NumPy I SciPy I Matplotlib/PylabIntroduction to Python Python What is Python? I Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. I Python is simple and easy to learn. I Python is open source, free and cross-platform. I Python provides high-level built in data structures. I Python is useful for rapid application development. I Python can be used as a scripting or glue language. I Python emphasizes readability. I Python supports modules and packages. I Python bugs or bad inputs will never cause a segmentation fault.Introduction to Python Python The language Features I Python programs are compiled to bytecode before interpretation (provide fast execution). I Python supports OS tools: environment variables, les, sockets, pipes, processes, threads, regular expressions, and so on. I Python comes with an interface to the Tk GUI called Tkinter. I Python runs as fast as Matlab (and sometimes faster).Introduction to Python Python The language More features (extract from the book "Learning Python") I Dynamic typing I Built-in object types I Built-in tools I Library utilities I Third-party utilities I Automatic memory managementIntroduction to Python Python Syntax Syntax I comments are indicated with "" I two statements on the same line are separated with a semicolon ";" I no semicolon at the end of lines I a long line continue on next with "n" (it is not always needed) I grouping is obtained through indentation I one Python script is considered a module that can be run or imported by other modules I assignment uses the equal sign "="Introduction to Python Python Syntax Assignment I Assignment creates references, not values: tmp = "hello"; tmp = 10 the first string will be deallocated I Contrary to C, assignment do not have value: y = (x = x + 1) is invalid I As in C: x += 1 is valid I Note that pre/post increment/decrement: x++; ++x; x; x are invalid I Multiple assignment (references to a unique object): x=y=z=1 I Multiple assignments: (x,y,z)=(3.5,5.5,'string') I Example of swaping variables value: (x,y)=(y,x)Introduction to Python Python Syntax Identi ers I First character: a letter or the symbol " " I Additional characters: alphanumeric or the symbol " " I They are case-sensitiveIntroduction to Python Python Syntax Documentation The rst unassigned string in a module, class declaration, or function declaration can be accessed through by using obj. doc where obj is the module, class, or function name. doc is one of Python special variables.Introduction to Python Python Syntax Special variables I Python relies on many special variables that can be accessed by your code. I One is the " name " variables. I When a module is run, it contains the string " main ". I When the module is imported, it contains the modules name. I You can add code that runs only when a module is called directly: if name == ' main ': test() I The use of special variables is an advanced topic. We won't talk about that too much.Introduction to Python Python Types Built-in object types Numbers : 3.1415, 1234, 999L, 3+4j Strings : 'spam', "guido's" Lists : 1, 2, 'three', 4 Dictionaries : f'food':'spam', 'taste':'yum'g Tuples : (1,'spam', 4, 'U') Files : text = open('eggs', 'r').read()Introduction to Python Python Types numbers integers 1234, -24, 0 unlimited precision integers 999999999999L oating 1.23, 3.14e-10, 4E210, 4.0e+210 oct and hex 0177, 0x9ff complex 3+4j, 3.0+4.0j, 3JIntroduction to Python Python Types strings (immutable sequences) single quote s1 = 'egg' double quotes s2 = "spam's" triple quotes block = """...""" concatenate s1 + s2 repeat s2 3 index,slice s2i, s2i:j length len(s2) formatting "a %s parrot" % 'dead' iteration for x in s2 x loop through each character of s2 membership 'm' in s2, return True if the 'm' is in the string s2Introduction to Python Python Types Lists I Ordered collections of arbitrary objects I Accessed by o set I Variable length, heterogeneous, arbitrarily nestable I Mutable sequence I Arrays of object referencesIntroduction to Python Python Types Lists operations empty list L = four items L2 = 0, 1, 2, 3 nested L3 = 'abc', 'def', 'ghi' index L2i, L3ij slice, length L2i:j, len(L2) concatenate, repeat L1 + L2, L2 3 iteration, membership for x in L2, 3 in L2 methods L2.append(4), L2.sort(), L2.index(1), L2.reverse() shrinking del L2k, L2i:j = assignment L2i = 1, L2i:j = 4,5,6 create list range(4), xrange(0, 4) useful to loopIntroduction to Python Python Types Dictionaries I Accessed by key, not o set I Unordered collections of arbitrary objects I Variable length, heterogeneous, arbitrarily nestable I Of the category mutable mapping I Tables of object references (hash tables)Introduction to Python Python Types Dictionaries operations empty d1 = fg two-item d2 = f'spam': 2, 'eggs': 3g nesting d3 = f'food': f'ham': 1, 'egg': 2gg indexing d2'eggs', d3'food''ham' methods d2.has key('eggs'), d2.keys(), d2.values() length len(d1) add/change d2key = new deleting del d2keyIntroduction to Python Python Types tuples I They are like lists but immutable. Why Lists and Tuples? I When you want to make sure the content won't change.

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.