Article Directory
Object Basics
Objects
- python is an object-oriented language, everything is an object in python;
- When the program is run, the data are loaded into memory and then run;
- The object is a container, is an area designated for storing data memory;
Structure of objects
Each object has three data python
id (identification)
- id used to distinguish objects, id number of each object is different from each other;
- Id function to view the object through the id ();
- python id generated by the parser, in the CPython, id is the object memory address;
- After the object is created, id change does not occur;
type (type)
- Type is the type of data object, such as int, bool, str, float;
- You can see the type of object type function ();
- Different types of objects having different functions;
- python is a strongly typed language, created after the object type can not be changed;
value
- Value is the data stored in the object;
- Subjects were divided into immutable objects and variable objects, object value can be a variable constant, immutable objects immutable values, generally objects are immutable;
Variables and objects
- python like objects from the object to the alias;
- No variable value stored object, but stored object id, i.e., objects in memory address;
- a=12,b=‘hello’
- When using a variable, that is, viewing the corresponding object by the object ID;
- Save the variable objects is changed after re-assignment;
- Are independent variables, modify a variable does not affect the other
Type Conversion
- The type of conversion is one type of object into another type of the object;
- Type conversion does not change the type of the object itself, but to create a new object before the object is the value assigned to it;
The type of conversion function
Type conversion functions will not affect the original object, but after converting the type of the object to the specified value returned as the return value;
int ()
-
Action: convert other types of objects to an int;
-
For strings, only when the string is transferred to an integer, the remaining character string can not be converted;
-
For floating point rounding down directly;
-
For bool type True, False, int (True) = 1, int (False) = 0;
float()
- Action: The other types of objects to a float;
- For strings, only when the string is integer, float to turn, rest of the string can not be converted;
- For the number of type int, can be added directly to 0.01, such as 12 becomes 12.0;
- For bool type True, False, float (True) = 1.0, int (False) = 0.0;
str()
- For any other type can be directly converted to a string
BOOL () - Action: convert to other objects bool value;
- All objects are represented by an empty conversion to False, as in int 0, float in 0.0, str of "", the remaining conversion is True; if