🗊Презентация Python

Нажмите для полного просмотра!
Python, слайд №1Python, слайд №2Python, слайд №3Python, слайд №4Python, слайд №5Python, слайд №6Python, слайд №7Python, слайд №8Python, слайд №9Python, слайд №10Python, слайд №11Python, слайд №12Python, слайд №13Python, слайд №14Python, слайд №15Python, слайд №16Python, слайд №17Python, слайд №18Python, слайд №19Python, слайд №20Python, слайд №21Python, слайд №22Python, слайд №23Python, слайд №24Python, слайд №25Python, слайд №26Python, слайд №27Python, слайд №28Python, слайд №29Python, слайд №30Python, слайд №31Python, слайд №32Python, слайд №33Python, слайд №34Python, слайд №35Python, слайд №36Python, слайд №37Python, слайд №38Python, слайд №39Python, слайд №40Python, слайд №41Python, слайд №42Python, слайд №43Python, слайд №44Python, слайд №45Python, слайд №46Python, слайд №47Python, слайд №48Python, слайд №49Python, слайд №50Python, слайд №51Python, слайд №52Python, слайд №53Python, слайд №54Python, слайд №55Python, слайд №56Python, слайд №57Python, слайд №58Python, слайд №59Python, слайд №60Python, слайд №61Python, слайд №62Python, слайд №63Python, слайд №64Python, слайд №65Python, слайд №66Python, слайд №67Python, слайд №68Python, слайд №69Python, слайд №70Python, слайд №71Python, слайд №72Python, слайд №73Python, слайд №74Python, слайд №75Python, слайд №76Python, слайд №77Python, слайд №78Python, слайд №79Python, слайд №80Python, слайд №81Python, слайд №82Python, слайд №83Python, слайд №84Python, слайд №85Python, слайд №86Python, слайд №87Python, слайд №88Python, слайд №89Python, слайд №90Python, слайд №91Python, слайд №92Python, слайд №93Python, слайд №94Python, слайд №95Python, слайд №96Python, слайд №97Python, слайд №98Python, слайд №99Python, слайд №100Python, слайд №101Python, слайд №102Python, слайд №103Python, слайд №104Python, слайд №105Python, слайд №106Python, слайд №107Python, слайд №108Python, слайд №109Python, слайд №110Python, слайд №111Python, слайд №112Python, слайд №113Python, слайд №114Python, слайд №115Python, слайд №116Python, слайд №117Python, слайд №118Python, слайд №119Python, слайд №120Python, слайд №121Python, слайд №122Python, слайд №123Python, слайд №124Python, слайд №125Python, слайд №126Python, слайд №127Python, слайд №128Python, слайд №129Python, слайд №130Python, слайд №131

Содержание

Вы можете ознакомиться и скачать презентацию на тему Python. Доклад-сообщение содержит 131 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Python
Vasiliy Kovalev
MERA - 2019
Описание слайда:
Python Vasiliy Kovalev MERA - 2019

Слайд 2





About Python
Описание слайда:
About Python

Слайд 3





What is Python?
A programming language
Open Source
Free; source code available
Download on your own system
Written by Guido van Rossum
Monty Python’s Flying Circus…
Описание слайда:
What is Python? A programming language Open Source Free; source code available Download on your own system Written by Guido van Rossum Monty Python’s Flying Circus…

Слайд 4





Features of Python
A script language
Interpreted
No compile/link stage
Write and run 
Slow compared to C, C++
Elegant design; “tight”
Designed for
Quick-and-dirty scripts
Reusable modules
Very large systems
Object-oriented
Very well-designed
But you don’t have to use it
Описание слайда:
Features of Python A script language Interpreted No compile/link stage Write and run Slow compared to C, C++ Elegant design; “tight” Designed for Quick-and-dirty scripts Reusable modules Very large systems Object-oriented Very well-designed But you don’t have to use it

Слайд 5





The Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.

There should be one — and preferably only one — obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than 'right now'.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!
Описание слайда:
The Zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one — and preferably only one — obvious way to do it. Although that way may not be obvious at first unless you’re Dutch. Now is better than never. Although never is often better than 'right now'. If the implementation is hard to explain, it’s a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea — let’s do more of those!

Слайд 6





Part 1:
Variables and built-in types
Описание слайда:
Part 1: Variables and built-in types

Слайд 7





Basic data types
Описание слайда:
Basic data types

Слайд 8





Useful functions
type(object) – returns type of an object
dir(object) – returns a list of attributes for an object
Описание слайда:
Useful functions type(object) – returns type of an object dir(object) – returns a list of attributes for an object

Слайд 9





Useful functions
help(object) – returns description of an object
Описание слайда:
Useful functions help(object) – returns description of an object

Слайд 10





Numeric types and literals
Описание слайда:
Numeric types and literals

Слайд 11





Numeric tools
Описание слайда:
Numeric tools

Слайд 12


Python, слайд №12
Описание слайда:

Слайд 13


Python, слайд №13
Описание слайда:

Слайд 14


Python, слайд №14
Описание слайда:

Слайд 15


Python, слайд №15
Описание слайда:

Слайд 16


Python, слайд №16
Описание слайда:

Слайд 17


Python, слайд №17
Описание слайда:

Слайд 18


Python, слайд №18
Описание слайда:

Слайд 19


Python, слайд №19
Описание слайда:

Слайд 20


Python, слайд №20
Описание слайда:

Слайд 21


Python, слайд №21
Описание слайда:

Слайд 22


Python, слайд №22
Описание слайда:

Слайд 23


Python, слайд №23
Описание слайда:

Слайд 24


Python, слайд №24
Описание слайда:

Слайд 25


Python, слайд №25
Описание слайда:

Слайд 26


Python, слайд №26
Описание слайда:

Слайд 27


Python, слайд №27
Описание слайда:

Слайд 28


Python, слайд №28
Описание слайда:

Слайд 29


Python, слайд №29
Описание слайда:

Слайд 30


Python, слайд №30
Описание слайда:

Слайд 31


Python, слайд №31
Описание слайда:

Слайд 32


Python, слайд №32
Описание слайда:

Слайд 33


Python, слайд №33
Описание слайда:

Слайд 34


Python, слайд №34
Описание слайда:

Слайд 35


Python, слайд №35
Описание слайда:

Слайд 36


Python, слайд №36
Описание слайда:

Слайд 37


Python, слайд №37
Описание слайда:

Слайд 38


Python, слайд №38
Описание слайда:

Слайд 39


Python, слайд №39
Описание слайда:

Слайд 40


Python, слайд №40
Описание слайда:

Слайд 41


Python, слайд №41
Описание слайда:

Слайд 42


Python, слайд №42
Описание слайда:

Слайд 43


Python, слайд №43
Описание слайда:

Слайд 44


Python, слайд №44
Описание слайда:

Слайд 45


Python, слайд №45
Описание слайда:

Слайд 46


Python, слайд №46
Описание слайда:

Слайд 47


Python, слайд №47
Описание слайда:

Слайд 48


Python, слайд №48
Описание слайда:

Слайд 49


Python, слайд №49
Описание слайда:

Слайд 50


Python, слайд №50
Описание слайда:

Слайд 51


Python, слайд №51
Описание слайда:

Слайд 52


Python, слайд №52
Описание слайда:

Слайд 53


Python, слайд №53
Описание слайда:

Слайд 54


Python, слайд №54
Описание слайда:

Слайд 55





Boolean expressions
‘True’ and ‘ False’ are predefined values; actually integers 1 and 0
Value 0 is considered False, all other values True
The usual Boolean expression operators: not, and, or
Описание слайда:
Boolean expressions ‘True’ and ‘ False’ are predefined values; actually integers 1 and 0 Value 0 is considered False, all other values True The usual Boolean expression operators: not, and, or

Слайд 56





String
Single quotes or double quotes can be used for string literals
Produces exactly the same value
Special characters in string literals: \n newline, \t tab, others
Triple quotes useful for large chunks of text in program code
Описание слайда:
String Single quotes or double quotes can be used for string literals Produces exactly the same value Special characters in string literals: \n newline, \t tab, others Triple quotes useful for large chunks of text in program code

Слайд 57





String conversions
Convert data types using functions ‘str’, ‘int’, ‘float’
‘repr’ is a variant of ‘str’
intended for strict, code-like representation of values
‘str’ usually gives nicer-looking representation
Function ‘eval’ interprets a string as a Python expression
Описание слайда:
String conversions Convert data types using functions ‘str’, ‘int’, ‘float’ ‘repr’ is a variant of ‘str’ intended for strict, code-like representation of values ‘str’ usually gives nicer-looking representation Function ‘eval’ interprets a string as a Python expression

Слайд 58





String operations
Common string operations on page 75 in ‘Learning Python’
Описание слайда:
String operations Common string operations on page 75 in ‘Learning Python’

Слайд 59





Changing strings. Not!
A string cannot be changed in Python! Immutable
Good reasons for this; more later
Create new strings from bits and pieces of old
Описание слайда:
Changing strings. Not! A string cannot be changed in Python! Immutable Good reasons for this; more later Create new strings from bits and pieces of old

Слайд 60





String methods
Strings have a set of built-in methods
No method ever changes the original string!
Several methods produce new strings
A list on page 91 in ‘Learning Python’
Описание слайда:
String methods Strings have a set of built-in methods No method ever changes the original string! Several methods produce new strings A list on page 91 in ‘Learning Python’

Слайд 61





List
Ordered collection of objects; array
Heterogenous; may contain mix of objects of any type
Описание слайда:
List Ordered collection of objects; array Heterogenous; may contain mix of objects of any type

Слайд 62





List operations
Lists are mutable; can be changed in-place
Lists are dynamic; size may be changed
Описание слайда:
List operations Lists are mutable; can be changed in-place Lists are dynamic; size may be changed

Слайд 63





List methods, part 1
Lists have a set of built-in methods
Some methods change the list in-place
Описание слайда:
List methods, part 1 Lists have a set of built-in methods Some methods change the list in-place

Слайд 64





List methods, part 2
Use the built-in 'sort' method: efficient
The list is sorted in-place; a new list is not produced!
Описание слайда:
List methods, part 2 Use the built-in 'sort' method: efficient The list is sorted in-place; a new list is not produced!

Слайд 65





Objects, names and references
All values are objects
A variable is a name referencing an object
An object may have several names referencing it
Important when modifying objects in-place!
You may have to make proper copies to get the effect you want
For immutable objects (numbers, strings), this is never a problem
Описание слайда:
Objects, names and references All values are objects A variable is a name referencing an object An object may have several names referencing it Important when modifying objects in-place! You may have to make proper copies to get the effect you want For immutable objects (numbers, strings), this is never a problem

Слайд 66





Dictionary
An unordered collection of key/value pairs
Each key maps to a value
Also called "mapping", "hash table" or "lookup table"
Описание слайда:
Dictionary An unordered collection of key/value pairs Each key maps to a value Also called "mapping", "hash table" or "lookup table"

Слайд 67





Forgetting things: garbage collection
What happens to the object when its name is ’del’ed, or reassigned to another object?
Don’t worry, be happy!
The Python systems detects when an object is ’lost in space’
It keeps track of the number of references to it
The object’s memory gets reclaimed; garbage collection
A few problematic special cases; cyclical references
Описание слайда:
Forgetting things: garbage collection What happens to the object when its name is ’del’ed, or reassigned to another object? Don’t worry, be happy! The Python systems detects when an object is ’lost in space’ It keeps track of the number of references to it The object’s memory gets reclaimed; garbage collection A few problematic special cases; cyclical references

Слайд 68





Dictionary methods, part 1
Описание слайда:
Dictionary methods, part 1

Слайд 69





Dictionary methods, part 2
Описание слайда:
Dictionary methods, part 2

Слайд 70





Tuple
Same as list, except immutable
Once created, can't be changed
Some functions return tuples
Описание слайда:
Tuple Same as list, except immutable Once created, can't be changed Some functions return tuples

Слайд 71





String formatting
Tuples are used as operands in string formatting when >1 items
The length of the tuple must match the number of format codes in the string
Lists won't do!
Описание слайда:
String formatting Tuples are used as operands in string formatting when >1 items The length of the tuple must match the number of format codes in the string Lists won't do!

Слайд 72





Part 2:
Statements
Описание слайда:
Part 2: Statements

Слайд 73





'if' statement; block structure
The Python feature that one either loves or hates
Block structure is determined by indentation
Edit a new script file 't2.py'
In window 't1.py' do 'File', 'New Window', then 'Save As…
Use the 'if' statement:
Описание слайда:
'if' statement; block structure The Python feature that one either loves or hates Block structure is determined by indentation Edit a new script file 't2.py' In window 't1.py' do 'File', 'New Window', then 'Save As… Use the 'if' statement:

Слайд 74





Dictionary often better than if… elif…
Particularly with many hardcoded choices (elif's)…
More compact, and more efficient
This pattern is very useful
Описание слайда:
Dictionary often better than if… elif… Particularly with many hardcoded choices (elif's)… More compact, and more efficient This pattern is very useful

Слайд 75





Built-in types and their Boolean interpretations
Описание слайда:
Built-in types and their Boolean interpretations

Слайд 76





'for' statement
Repetition of a block of statements
Iterate through a sequence (list, tuple, string, iterator)
Описание слайда:
'for' statement Repetition of a block of statements Iterate through a sequence (list, tuple, string, iterator)

Слайд 77





Built-in functions 'range' and 'xrange'
Built-in functions 'range' and 'xrange' useful with 'for'
'range' creates a list
Warning: may use lots of memory; inefficient!
Описание слайда:
Built-in functions 'range' and 'xrange' Built-in functions 'range' and 'xrange' useful with 'for' 'range' creates a list Warning: may use lots of memory; inefficient!

Слайд 78





'while' statement
Repetition of a block of statements
Loop until test becomes false, or 'break'
Описание слайда:
'while' statement Repetition of a block of statements Loop until test becomes false, or 'break'

Слайд 79





Optional 'else' block in loops
'else' block executed if no 'break' encountered
May often replace success/failure flags
Valid in 'for' and 'while' loops
Описание слайда:
Optional 'else' block in loops 'else' block executed if no 'break' encountered May often replace success/failure flags Valid in 'for' and 'while' loops

Слайд 80





Error handling: ’try’ and ’except’
Run-time error normally causes execution to bomb
The error message gives type of error
Use a ’try’, ’except’ blocks to catch and handle errors
Описание слайда:
Error handling: ’try’ and ’except’ Run-time error normally causes execution to bomb The error message gives type of error Use a ’try’, ’except’ blocks to catch and handle errors

Слайд 81





How to split up long lines
Sometimes a source code line needs splitting up
Indentation rule means we do not have free-format!
Описание слайда:
How to split up long lines Sometimes a source code line needs splitting up Indentation rule means we do not have free-format!

Слайд 82





Statements not covered in this course
'finally': used with 'try', 'except'
'raise': causes an exception
'yield': in functions
'global': within functions
'exec': execute strings as code
There is no 'goto'  statement!
Описание слайда:
Statements not covered in this course 'finally': used with 'try', 'except' 'raise': causes an exception 'yield': in functions 'global': within functions 'exec': execute strings as code There is no 'goto' statement!

Слайд 83





Part 3:
Functions
Описание слайда:
Part 3: Functions

Слайд 84





How to define your own function
Use the 'def' statement
Function body follows; indented!
This is a statement like others
Can be placed basically anywhere
Required: Define the function before calling it
Описание слайда:
How to define your own function Use the 'def' statement Function body follows; indented! This is a statement like others Can be placed basically anywhere Required: Define the function before calling it

Слайд 85





Function features
The value of an argument is not checked for type
Often very useful; overloading without effort
Of course, the function may still bomb if invalid value is given
The documentation string is not required (more later)
But strongly encouraged!
Make a habit of writing one (before writing the function code)
A user-defined function has exactly the same status as a built-in function, or a function from another module
Описание слайда:
Function features The value of an argument is not checked for type Often very useful; overloading without effort Of course, the function may still bomb if invalid value is given The documentation string is not required (more later) But strongly encouraged! Make a habit of writing one (before writing the function code) A user-defined function has exactly the same status as a built-in function, or a function from another module

Слайд 86





Function arguments: fixed
Fixed number of arguments
Associated by order
Описание слайда:
Function arguments: fixed Fixed number of arguments Associated by order

Слайд 87





Function arguments: variable
List of any number of arguments
Useful when unknown number of arguments needed
The argument values collected into a tuple
Called 'args', by convention
The ’*’ is the magical part
Описание слайда:
Function arguments: variable List of any number of arguments Useful when unknown number of arguments needed The argument values collected into a tuple Called 'args', by convention The ’*’ is the magical part

Слайд 88





Function arguments: default values
Arguments may have default values
When argument not given in a call, default value is used
If no default value, and not given when called: bombs
Use explicit names to override argument order
Описание слайда:
Function arguments: default values Arguments may have default values When argument not given in a call, default value is used If no default value, and not given when called: bombs Use explicit names to override argument order

Слайд 89





Function arguments: keywords
Keyword/value arguments
The argument values collected into a dictionary
Called 'kwargs', by convention
The ’**’ is the magical part
First attempts to match existing argument names
Описание слайда:
Function arguments: keywords Keyword/value arguments The argument values collected into a dictionary Called 'kwargs', by convention The ’**’ is the magical part First attempts to match existing argument names

Слайд 90





Function arguments: local variables
Arguments become local variables
Immutable values are copied, in effect
Mutable values may still be changed: be careful
Variables created within 'def' block are local
Forgotten on return
Описание слайда:
Function arguments: local variables Arguments become local variables Immutable values are copied, in effect Mutable values may still be changed: be careful Variables created within 'def' block are local Forgotten on return

Слайд 91





Function without 'return': value None
A function does not have to use the 'return' statement
If not, then same as a 'procedure' in other languages
Actually returns a value anyway: 'None'
A 'return' without value is OK: returns 'None'
'None' is a special value meaning 'nothing'
Useful in many contexts
Particularly in object-oriented programming (more later)
Описание слайда:
Function without 'return': value None A function does not have to use the 'return' statement If not, then same as a 'procedure' in other languages Actually returns a value anyway: 'None' A 'return' without value is OK: returns 'None' 'None' is a special value meaning 'nothing' Useful in many contexts Particularly in object-oriented programming (more later)

Слайд 92





The 'math' module: functions and constants
A peek at modules
Math functions available in a separate module
Описание слайда:
The 'math' module: functions and constants A peek at modules Math functions available in a separate module

Слайд 93





Functions are objects; names are references
A function is just another kind of object
Nothing magical about their names; can be changed
Описание слайда:
Functions are objects; names are references A function is just another kind of object Nothing magical about their names; can be changed

Слайд 94





Built-in function 'map'
Built-in function that works on a list
'map' takes a function and a list
The function must take only one argument, and return one value
The function is applied to each value of the list
The resulting values are returned in a list
Описание слайда:
Built-in function 'map' Built-in function that works on a list 'map' takes a function and a list The function must take only one argument, and return one value The function is applied to each value of the list The resulting values are returned in a list

Слайд 95





Built-in function 'reduce'
Описание слайда:
Built-in function 'reduce'

Слайд 96





Built-in function 'filter'
Описание слайда:
Built-in function 'filter'

Слайд 97





Files: reading
A file object is created by the built-in function 'open'
The file object has a set of methods
The 'read' methods get data sequentially from the file
'read': Get the entire file (or N bytes) and return as a single string
'readline': Read a line (up to and including newline)
'readlines': Read all lines and return as a list of strings
Описание слайда:
Files: reading A file object is created by the built-in function 'open' The file object has a set of methods The 'read' methods get data sequentially from the file 'read': Get the entire file (or N bytes) and return as a single string 'readline': Read a line (up to and including newline) 'readlines': Read all lines and return as a list of strings

Слайд 98





Files: writing
The 'write' method simply outputs the given string
The string does not have to be ASCII; binary contents allowed
Описание слайда:
Files: writing The 'write' method simply outputs the given string The string does not have to be ASCII; binary contents allowed

Слайд 99





Part 4:
Modules
Описание слайда:
Part 4: Modules

Слайд 100





Example: Reverse complement NT sequence
Given a nucleotide sequence, produce reverse complement
Use available features
Описание слайда:
Example: Reverse complement NT sequence Given a nucleotide sequence, produce reverse complement Use available features

Слайд 101





Make a module of the code
How to make the code even more reusable?
Step 2: Make a module out of it
Is actually already a module!
Let’s simply rename it to ’ntseq.py’
Описание слайда:
Make a module of the code How to make the code even more reusable? Step 2: Make a module out of it Is actually already a module! Let’s simply rename it to ’ntseq.py’

Слайд 102





How to use the module: ’import’ statement
The ’import’ statement makes a module available
The module name (not the file name) is imported: skip the ’.py’
Access module features through the ’dot’ notation
Описание слайда:
How to use the module: ’import’ statement The ’import’ statement makes a module available The module name (not the file name) is imported: skip the ’.py’ Access module features through the ’dot’ notation

Слайд 103





Module self-test code: the ’__name__’ trick
The ’import’ statement executes all code in the module file
How to ’hide’ self-test code?
Use the predefined variable ’__name__’:
If executed as the main program: value ’__main__’
If executed as a module: some other value
Описание слайда:
Module self-test code: the ’__name__’ trick The ’import’ statement executes all code in the module file How to ’hide’ self-test code? Use the predefined variable ’__name__’: If executed as the main program: value ’__main__’ If executed as a module: some other value

Слайд 104





Now, the ’import’ statement behaves
Описание слайда:
Now, the ’import’ statement behaves

Слайд 105





Modules are easy, fun, and powerful
The module feature is the basis for Python's ability to scale to really large software systems
Easy to create: every Python source code file is a module!
Features to make a module elegant:
Doc strings
'__name__' trick
Namespace concept
Be sure to browse the standard library modules!
You will find extremely useful stuff there
You will learn good coding habits
Packages are directories of several associated modules
Not covered in this course. A few minor interesting points
Описание слайда:
Modules are easy, fun, and powerful The module feature is the basis for Python's ability to scale to really large software systems Easy to create: every Python source code file is a module! Features to make a module elegant: Doc strings '__name__' trick Namespace concept Be sure to browse the standard library modules! You will find extremely useful stuff there You will learn good coding habits Packages are directories of several associated modules Not covered in this course. A few minor interesting points

Слайд 106





Namespaces
A namespace is a bag of names
A module is a namespace
Use the built-in function ’dir’ to list the names in a namespace
’import’ statement modifies the namespace
Описание слайда:
Namespaces A namespace is a bag of names A module is a namespace Use the built-in function ’dir’ to list the names in a namespace ’import’ statement modifies the namespace

Слайд 107





Avoiding clutter in your namespace
Using ’from module import *’ can create clutter
Fine-tuning of import; bring in only selected things
Rename things from a module
Avoid name collisions
Make it clearer
Описание слайда:
Avoiding clutter in your namespace Using ’from module import *’ can create clutter Fine-tuning of import; bring in only selected things Rename things from a module Avoid name collisions Make it clearer

Слайд 108





Doc strings: ’__doc__’
We have mentioned documentation strings before
The first string in a module
The first string after a ’def’ statement
Accessed through variable ’__doc__’
Feature to facilitate creation of documentation
Used by tools to produce documentation, such as ’pydoc’
See ’Module Docs’ in ’Start’ > ’Programs’ > ’Python 2.3’
Описание слайда:
Doc strings: ’__doc__’ We have mentioned documentation strings before The first string in a module The first string after a ’def’ statement Accessed through variable ’__doc__’ Feature to facilitate creation of documentation Used by tools to produce documentation, such as ’pydoc’ See ’Module Docs’ in ’Start’ > ’Programs’ > ’Python 2.3’

Слайд 109





Part 5:
Object-oriented programming, classes
Описание слайда:
Part 5: Object-oriented programming, classes

Слайд 110





Classes vs. objects (instances)
A class is like a
Prototype
Blue-print ("ritning")
An object creator
A class defines potential objects
What their structure will be
What they will be able to do
Objects are instances of a class
An object is a container of data: attributes
An object has associated functions: methods
Описание слайда:
Classes vs. objects (instances) A class is like a Prototype Blue-print ("ritning") An object creator A class defines potential objects What their structure will be What they will be able to do Objects are instances of a class An object is a container of data: attributes An object has associated functions: methods

Слайд 111





A class example: Geometrical shapes
Let's define classes for geometrical shapes
With data; position, etc
With functions: compute area, etc
Описание слайда:
A class example: Geometrical shapes Let's define classes for geometrical shapes With data; position, etc With functions: compute area, etc

Слайд 112





Instances of classes
Let's create some instances of the Circle class
Look at attribute 'radius'
Use the method 'area'
Описание слайда:
Instances of classes Let's create some instances of the Circle class Look at attribute 'radius' Use the method 'area'

Слайд 113





Changing an instance: references
Variables may reference the same object
Changing an attribute changes the object, not the reference
Описание слайда:
Changing an instance: references Variables may reference the same object Changing an attribute changes the object, not the reference

Слайд 114





Changing an instance: attribute add/delete
An attribute can be added!
And deleted!
Описание слайда:
Changing an instance: attribute add/delete An attribute can be added! And deleted!

Слайд 115





Equality between objects
Two kinds of equality:
Are the two objects similar in value?
Are the two references actually pointing to the same object?
Описание слайда:
Equality between objects Two kinds of equality: Are the two objects similar in value? Are the two references actually pointing to the same object?

Слайд 116





Special methods in classes
Special methods '__xxx__' in classes
Define custom-made behaviour
See page 327 in 'Learning Python'
Описание слайда:
Special methods in classes Special methods '__xxx__' in classes Define custom-made behaviour See page 327 in 'Learning Python'

Слайд 117





Using the special methods, part 1
Special method definitions are detected by Python
Built-in functions use them; see documentation
Описание слайда:
Using the special methods, part 1 Special method definitions are detected by Python Built-in functions use them; see documentation

Слайд 118





Using the special methods, part 2
Defining special methods may clarify code tremendously
But: Stay reasonable 'natural'!
Описание слайда:
Using the special methods, part 2 Defining special methods may clarify code tremendously But: Stay reasonable 'natural'!

Слайд 119





Inheritance: Class hierarchies
Let's define a general 'Shape' class
'Circle' is a special case of 'Shape'
'Blob' is also a special case of 'Shape'
Notice: redefinition of 'is_round' in 'Blob'
Описание слайда:
Inheritance: Class hierarchies Let's define a general 'Shape' class 'Circle' is a special case of 'Shape' 'Blob' is also a special case of 'Shape' Notice: redefinition of 'is_round' in 'Blob'

Слайд 120





Instances of classes using inheritance
Which method is called by which instance?
Polymorphism
Selection of method depends on actual class of the instance
Extremely powerful, if properly designed class hierarchy
Описание слайда:
Instances of classes using inheritance Which method is called by which instance? Polymorphism Selection of method depends on actual class of the instance Extremely powerful, if properly designed class hierarchy

Слайд 121





Part 6:
Standard library modules
Описание слайда:
Part 6: Standard library modules

Слайд 122





Module 're', part 1
Define a pattern
The pattern syntax is very much like Perl or grep
Apply it to a string
Process the results
Описание слайда:
Module 're', part 1 Define a pattern The pattern syntax is very much like Perl or grep Apply it to a string Process the results

Слайд 123





Module 'sys', part 1
sys.argv
List of command-line arguments; sys.argv[0] is script name
sys.path
List of directory names, where modules are searched for
sys.platform
String to identify type of computer system
Описание слайда:
Module 'sys', part 1 sys.argv List of command-line arguments; sys.argv[0] is script name sys.path List of directory names, where modules are searched for sys.platform String to identify type of computer system

Слайд 124





Module 'sys', part 2
sys.stdout, sys.stdin, sys.stderr
Predefined file objects for input/output
'print' stuff goes to 'sys.stdout'
May be set to other files
sys.exit(n)
Force exit from Python execution
'n' is an integer error code, normally 0
Описание слайда:
Module 'sys', part 2 sys.stdout, sys.stdin, sys.stderr Predefined file objects for input/output 'print' stuff goes to 'sys.stdout' May be set to other files sys.exit(n) Force exit from Python execution 'n' is an integer error code, normally 0

Слайд 125





Module 'os', part 1
os.getcwd()
Returns the current directory
Описание слайда:
Module 'os', part 1 os.getcwd() Returns the current directory

Слайд 126





Module 'os', part 2
os.chdir(path)
Changes the current working directory to 'path'
os.listdir(path)
Return a list of the contents of the directory 'path'
os.mkdir(path)
Create the directory 'path'
os.rmdir(path)
Remove the directory 'path'
os.remove(path)
Remove the file named 'path'
Описание слайда:
Module 'os', part 2 os.chdir(path) Changes the current working directory to 'path' os.listdir(path) Return a list of the contents of the directory 'path' os.mkdir(path) Create the directory 'path' os.rmdir(path) Remove the directory 'path' os.remove(path) Remove the file named 'path'

Слайд 127





Module 'os', part 3
os.system(command)
Execute the shell command (string) in a subprocess
Return the error code as integer
os.popen(command, mode='r')
Run the shell command (string)
Open a pipe to the command, return as a file object
Mode is either read, or write; not both
os.popen2, os.popen3, os.popen4
Variants of os.popen, with different file objects
os.getpid()
Return the process ID as integer
Описание слайда:
Module 'os', part 3 os.system(command) Execute the shell command (string) in a subprocess Return the error code as integer os.popen(command, mode='r') Run the shell command (string) Open a pipe to the command, return as a file object Mode is either read, or write; not both os.popen2, os.popen3, os.popen4 Variants of os.popen, with different file objects os.getpid() Return the process ID as integer

Слайд 128





Module 'os.path', part 1
os.path.abspath(path)
Returns the absolute path for the given relative 'path'
Описание слайда:
Module 'os.path', part 1 os.path.abspath(path) Returns the absolute path for the given relative 'path'

Слайд 129





Module 'os.path', part 2
os.path.join(path, path, …)
Joint together the path parts intelligently into a valid path name
Описание слайда:
Module 'os.path', part 2 os.path.join(path, path, …) Joint together the path parts intelligently into a valid path name

Слайд 130





Module 'os.path', part 3
os.path.isfile(path)
Is 'path' the name of a file?
os.path.isdir(path)
Is 'path' the name of a directory?
Описание слайда:
Module 'os.path', part 3 os.path.isfile(path) Is 'path' the name of a file? os.path.isdir(path) Is 'path' the name of a directory?

Слайд 131





Some other useful modules
Описание слайда:
Some other useful modules



Теги Python
Похожие презентации
Mypresentation.ru
Загрузить презентацию