python

类型转换四个函数

int() float() str() bool()

算数运算

// 除法,取整

** 幂运算符, 去几次幂

% 取模

赋值

  • +=
  • -=
  • *=
  • **=
  • /=
  • //=
  • %=

关系运算符

Python中可以对字符串进行大于或小于与的运算。

当比较字符串时,比较的是unicode编码,逐位比较。按照此特性,可以进行英文字母排序比较,中文来说是不很好,因为有的是按笔画有的是按偏旁部首。

is 比较对象,(id)

is not 比较对象

逻辑运算符

短路操作, and 找false,第一个找不到会继续运行

or 找 true , 第一个找到不会继续运行

三元运算符

print(“hello”) if True else print(“world”);

如果是true执行前面,否则执行else的

max = a if a > b else b

max = a if (a > b and a > c) else (b if b > c else c)

流程控制语句

res = 1 < 2 < 3

用中间比较左右两边

RSA证书生成命令

test -d certs && rm -rf certs
 mkdir certs
 cd certs
 openssl genrsa -out rsa_private_key.pem 1024
 openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
 openssl pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt > rsa_private_key_pkcs8.pem
 openssl req -new -x509 -key rsa_private_key.pem -out ca.crt -days 7300
 openssl req -new -key rsa_private_key.pem -out request.csr
 openssl x509 -req -days 7300 -in request.csr -CA ca.crt -CAkey rsa_private_key.pem -CAcreateserial -out rsa_public_crt.crt
 rm -f ca.crt
 rm -f request.csr
 echo '-----------------------------------------------'
 echo '*  Success! Check out files in certs folder.  *'
 echo '-----------------------------------------------'