Python01

Python01

Integer
Float
String
Boolean
Null
Variable dynamic language
Constant uppercase is not guaranteed not to be changed

There is no limit to the size of integers and floating-point numbers
. The result of integer division of floating
-point numbers is absolutely accurate. There is normal division. The division of two integers is a floating-point number
. There is floor division.
Division rounds up and is imprecise.

Character Encoding

list

The last element
class[-1]
The penultimate
class[-2]
variable length

tuple

List []
tuple ()
is immutable after initialization, and an element must be added to
define it,
so it is safer to be immutable

judge

if xxx:
    xxx
elif xxx:
    xxx
else:
    xxx

if x:
tudo
x is non-null, non-zero, true

cycle

for in
while
don't use continue and break too much

dict

{}
dictionary, that is, map, key-value pair
By 'key' in dictjudging whether the key exists, the
space complexity is high, and the space
key is immutable

set

s = set([1,2,3])
unordered without repetition, the input is
the key of the list hash, there is no value
so the key is immutable

immutable object

str
mutable object list

function

def

pass

Placeholder

Function parameters:

Positional parameters
abs(x)
Default parameters
power(x, n = 2)
, simplify function calls, and write them at the end.
Default parameters must be immutable objects
. When writing out of sequence, you need to write parameter names.
Pit : The default parameters are variable objects, such as list, when using the default values ​​of default parameters , the reference to the parameter is unchanged, but the content has changed

variable parameter*

Essentially a tuple
Definition : sum(*nums)
call:sum(1,2,3)
sum(1,2)

nums = (1,2)
sum(*nums)```
简化传递参数过程,不用再先写一个容器tuple
###关键字参数**
实质上是dict
定义`person(name, age **extra)`
调用:
`person("liu" 28, city = "beijing", home = "changping")`
或者:
```extra = { city = "beijing", home = "cangping"}
person("liu", 28, **extra)

sys.exit()

numpy installation problem

The pip tool is
not installed. The
system has python3.6 installed,
but this has nothing to do with
pycharm. pycharm has its own python
and needs to install numpy in pycharm

global

declare a global variable

tail recursion

python doesn't have tail recursion

recursion

It is possible that the stack will be full and overflow

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325587223&siteId=291194637