Related terms for Python objects:
All the data stored in a Python program is built around the concept of the object.
All data stored in the program is an object
Each object has an identity, a type, and a value
For example, school= "MaGe Linux" creates a string object with "MaGe Linux" whose identity is a pointer to its location in memory (its address in memory), and school is the name that refers to that particular location.
in [+]: name= "Herry" in []: ID (name) out[15]: 40364672In [+]: type (name) out[16]: str
The type of an object also becomes the category of the object that describes the internal representation of the object and the methods and actions it supports to create a particular type of object, and sometimes the instance of the object that becomes the type is created, and its identity and type cannot be changed
If the object is modifiable, it is called a mutable object
If the value of an object cannot be changed, it is called an immutable object
If an object contains references to other objects, it is called a container most objects have a large number of unique data properties and methods
Properties: Values associated with an object
Method: A function that will perform certain operations on an object when called
Use (.) Operators can access properties and methods
Classes: Data and methods
Data: Variables
Method: function
Class (instantiated as an object)
Python built-in function ID () returns the identity of an object, both in-memory location
#两个对象比较: #1. Value comparison: Whether the data in the object is the same #2. Identity comparison: Two variable names refer to the same object #3. Type comparison: Two objects are of the same type in []: name1= "Tom" in [Max]: name2= "Tom" in [+]: name3= "Jack" in [[]: name1==name2out[24]: Truein []: Name1 is name2out[20]: Truein []: Name1 is name3out[21]: Fa Lsein [+]: type (NAME1) is type (name2) out[22]: True
Python Core Data type:
Numbers: Int,log,float,complex,bool
Character: Str,unicode
Listing: List
Tuples: Tuple
Files: File
Other types: Collection (set), Fronzenset, class type, none
Other file class Tools: Pipes (Pipeline), FIFO (first in, out pipe), sockets (socket)
The type of the object is itself an object, called the class of the object
The definition of the object is unique and is the same for all instances of a type
All types of objects have a specified name that can perform type checking, such as List,dict
Type conversions:
str (),repr ( ), or format (): Converts non-character data to characters:
In []: name1==name2out[24]: Truein [+]: num1=5.61in [+]: type (NUM1) out[26]: Floatin [+]: str (NUM1) out[27]: ' 5.61 ' in [ : num1=5.61in []: Str1=repr (NUM1) in [+]: type (STR1) out[30]: str
Int (): Convert to Integer
Float (): Convert to floating point
List (s): Convert string S to list
Tuples (s): convert string s to Narimoto group
Set (s): Convert string S to collection
Dict (d): Create dictionary, where D is (key,value) tuple
In [31]: str2= "In [33]: type" (str2) Out[33]: strin [34]: num3=int (STR2) in [35]: type (num3) out[35]: intin [36]: num4=float (str2) in [37]: type (NUM4) out[37]: floatin [38]: str3= "Whats you name" #将字符穿转换列表 (list) type in [39]: l1= List (STR3) in [40]: print l1[' W ', ' h ', ' a ', ' t ', ' s ', ' ', ' Y ', ' o ', ' u ', ' ', ' n ', ' a ', ' m ', ' e ']in [41]: str4= ' whats the fuck "#将字符串转换为元组In [42]: t1=tuple (STR4) in [44]: print t1 (' W ', ' h ', ' a ', ' t ', ' s ', ' ', ' t ', ' h ', ' e ', ' ', ' f ', ' u ', ' C ', ' K ') #将字符串转换成集合In [45]: print str4whats the fuckin [46]: s1= Set (STR4) In [47]: print s1set ([' A ', ' ', ' C ', ' e ', ' F ', ' H ', ' K ', ' s ',   ' U ', ' t ', ' W ') #将数组转换成字典In [51]: l3=[(' A ', 1), (' B ', '), (' C ', ', ')]in [52]: print l3[(' A ', 1), (' B ', 22), (' C ', 56)]in [53]: d1=dict (L3) in [54]: print d1{' A ': 1, ' C ': 56, ' B ': 22}
This article from the "Linux Revolution" blog, reproduced please contact the author!
Python Learning Notes (iv) Python object types and their operations