Home  >  Article  >  Backend Development  >  Basic knowledge of python syntax

Basic knowledge of python syntax

王林
王林Original
2019-10-29 17:03:2811255browse

Basic knowledge of python syntax

1. Numeric types and operations

1. Integer types

can be positive or negative, with no limit on the value range

pow(x,y):计算x^y

2. Floating point number type

There is an uncertain mantissa

round(x,d):对x四舍五入,d为小数截取位数
<a>e/E<b>:a*10^b

3. Complex number type

z=a+bj
z.real=a    z.imag=b

2. Numerical operation operator

eg:x//y :整数除 10//3=3 x%y :求模  10%3=1 x**y=x^y

3. Numerical operation function

abs(x) :绝对值  abs(-10)=10
divmod(x,y) :商余  divmod(10,3)=(3,1)
pow(x,y,z) :幂余,(x**y)%z
max(x1,x2,...xn) :求最大值 min(x1,x2,...xn) :求最小值
int(x) :将x变成整数 float(x) :将x变成浮点数
comlex(x) :将x变成浮点数

4. Representation of string type (consisting of a pair of single quotes or An ordered sequence of characters represented by double quotes)

f7e83be87db5cd2d9a8a0b8117b38cd4[M:N:K], slice the string according to the step size K

Special characters: "\b ": Go back "\n": Line feed (the cursor moves to the beginning of the next line) "\r": Carriage return (the cursor moves to the beginning of this line)

5. String processing function

len(x): length str(x): string form corresponding to any type x

chr(x): x is Unicode encoding, return its corresponding character ord (x) : On the contrary

Recommended tutorial: python tutorial

The above is the detailed content of Basic knowledge of python syntax. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn