Home > Backend Development > Python Tutorial > Basic knowledge of python syntax

Basic knowledge of python syntax

王林
Release: 2019-10-29 18:06:53
Original
11359 people have browsed it

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
Copy after login

2. Floating point number type

There is an uncertain mantissa

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

3. Complex number type

z=a+bj
z.real=a    z.imag=b
Copy after login

2. Numerical operation operator

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

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变成浮点数
Copy after login

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

[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!

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template