关于Python的一些知识点

关于'='操作符:
1. We need to bear in mind this fact that the = operator performs a binding operation rather than an assignment.The name on the left-hand side is bound (or re-bound if the name already exists) to the object on the right-hand side.
----------------------------------------------------------------
关于进制标书:
Integer literals are assumed to be base 10 (decimal) numbers, except those that start with a 0x which are treated as hexadecimal (base 16), for example 0x3F which is decimal 63,and those that start with 0 which are treated as octal (base . Any kind of integer literal can have L appended to it to make it into a long.
----------------------------------------------------------------

字符转换:
chr(), 参数范围:0-255   <-------> ord()
chr(i) Returns a one character str whose ASCII value is given by integer i

ord(c) Returns the integer that is the byte value (0–255) if c is a one character 8-bit string, or the integer for the Unicode code point if c is a one character Unicode string


unichr(),参数范围:0-65535   <-------->ord()
unichr(i) Returns a one character unicode string whose Unicode value is given by integer i
----------------------------------------------------------------
Index:
Negative indexes are used to access characters from right-to-left, with the rightmost
character position being -1, the one to the left of that at position -2, and so on.
----------------------------------------------------------------

Shallow and Deep Copying:
If we create a list with two variables referring to it, and change the
list through one of the variables, both variables now refer to the same changed
list:

>>> seaweed = ["Aonori", "Carola", "Dulse"]
>>> macroalgae = seaweed
>>> seaweed, macroalgae
(['Aonori', 'Carola', 'Dulse'], ['Aonori', 'Carola', 'Dulse'])
>>> macroalgae[2] = "Hijiki"
>>> seaweed, macroalgae
(['Aonori', 'Carola', 'Hijiki'], ['Aonori', 'Carola', 'Hijiki'])

This is because by default Python uses shallow copying when copying mutable
data. We can force Python to do a deep copy by taking a slice that consists of the
entire list:

>>> seaweed = ["Aonori", "Carola", "Dulse"]
>>> macroalgae = seaweed[:]
>>> seaweed, macroalgae
(['Aonori', 'Carola', 'Dulse'], ['Aonori', 'Carola', 'Dulse'])
>>> macroalgae[2] = "Hijiki"
>>> seaweed, macroalgae
(['Aonori', 'Carola', 'Dulse'], ['Aonori', 'Carola', 'Hijiki'])
----------------------------------------------------------------


猜你喜欢

转载自louis-lu.iteye.com/blog/2307270