This collation Python data type is:
-
Lists List
-
Dictionary Dict
-
Tuple tuples
-
Set Set
It involves the concept of:
-
Module module
-
Classes Class
-
Objects Object
——————————————————————————————————————————
DataType type
Tuple tuples
Immutable sequences
How to create
(' A ',)
Tuple (' abc ')
Call Data Mode
T[0] is called the first character, and so on
Lists List
Variable sequence
How to create
List (' abc ')
[' A ']
Call Data Mode
L[0] is called the first character, and so on
Slice: list[strat:end:steps]
Dictionary Dict
Key:vaule Collection
How to create
Dict (Key:vaule)
{' A ': 1}
Call Data Mode
D[' A '] is invoked on key to invoke Vaule
Set Set
Unordered hash character sequence, non-repeating
Remove list duplicate data: List (set (' A ', ' a ', ' B '))
How to create
Set (' abc ')
Set operation
The collection |
Intersection &
Difference Set-
Differential set ^
Module module
A python file that contains functions and variables that can be called simultaneously by multiple scripts
Invocation mode
Import (module name)
Use functions: module name. function name
Import (module name) as (new module name)
Import (function name) from (module name)
function can be used directly
__name__ Property
The default value is "__main__", which becomes the module name after import
if __name__ = = ' __main__ ':
print ' This program was being run by itself '
Else
print ' I am being imported from another module '
Classes Class
Objects with the same properties and methods
Class is equivalent to a built-in module that can be called multiple times within the current script
__init__ function
This function is called when creating an instance of the class (Calling the Class), where the initialization of the object can be implemented
Necessary?
Formal parameter Self
A class is like a blueprint, using a class can create multiple object instances, and the Self argument tells which object is called, which is called the instance invocation
>>> class PEO:
def __init__ (self,name,age,sex):
Self. Name = Name
Self. Age = Age
Self. sex = Sex
def speak (self):
print "My name" + self. Name
>>> Zhangsan=peo ("Zhangsan", +, ' man ')
>>> print Zhangsan. Age
24
>>> Zhangsan.speak ()
My Namezhangsan
>>> Peo.speak (Zhangsan)
My Namezhangsan
Python Basic Concept Learning notes