1, Python string output there are many kinds. A= ' name:{0},age:{1},sex:{2} '. Format (name,age,sex) First
Name= "Lijiaxiang"
Age=12
sex= "Male"
A= ' Name:{_name},age:{_age},sex:{_sex} '. Format (_name=name,_age=age,_sex=sex) the second type
String also has a + number stitching. This is the least recommended. Because both of the above are in memory to open up specific memory, but the + number is open a lot of memory. So this is the least recommended. So forget this stitching method
2, deep copy and shallow copy difference: Before learning Java also read deep copy and shallow copy, but then never understand what is deep copy, what is shallow copy, yesterday listen to the old boy course, Alex Teacher told an example, I feel particularly easy to understand. The so-called shallow copy, is only copied the most outer layer . Deep replication, however, can be said to be a complete copy of the entire content (this is what we imagined copying). So what does it mean to replicate the outer layer? To give a simple example:
#encoding: Utf-8
Import Copy
a=["Kalson", [15,25], "male"]
B=copy.copy (a)
Print a
Print B
a[0]= "Kangkang"
A[1][0]=18
B[0]= "Mike"
Print a
Print B
=========================== results are as follows ===========
[' Kalson ', [[], ' Male ']
[' Kalson ', [[], ' Male ']
['Kangkang', [+], ' male ']
['Mike', [+], ' male ']
As you can see, for the outermost layer, after the replication is not relevant, a in the Kalson-->kangkang,b kalson-->mike. But only in a to modify the 15-->18,b is also modified. This means that for [18,25], because this is not a basic data type, in fact a is the address that stores [15,25]. So this is another layer. And this layer, with simple copy shallow copy has gone.
Does not know whether can let the people understand better? Anyway, it was a more definite understanding for me. The first time to write a blog, there is no clear statement also please friends forgive me.
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/9C/9F/wKiom1lzXRSw8gXlAAAMVJ0M2D4192.png-wh_500x0-wm_ 3-wmp_4-s_2361098106.png "title=" 123.png "alt=" Wkiom1lzxrsw8gxlaaamvj0m2d4192.png-wh_50 "/>
This article is from the "Let the past like Smoke" blog, please be sure to keep this source http://kalson.blog.51cto.com/12267030/1950083
Python Basics with learning notes