Basic data types used Python3

In Python variable is a variable, it is not the type we call "type" is the type of objects in memory within the meaning of the variables; variables need not be declared. Each variable must be assigned before use variable assignment after the variable will be created

Single variable assignment

#!/usr/bin/python3
counter = 100          # 整型变量
miles   = 1000.0       # 浮点型变量
name    = "Liquor"     # 字符串
print (counter,miles,name)
#输出结果:
100  1000.0  Liquor

Multiple variable assignment

Python allows you to assign the same time as a number of variables such as:

#!/usr/bin/python3
a, b, c = 1, 2, "Liquor"
print(a,b,c)
#输出结果
1 2 Liquor

Python3 There are six standard data types:

Immutable data (3): Number (number), String (String), Tuple (tuple);

Variable data (3): List (list), Dictionary (dictionary), Set (collection)

A, Number (digital)

Python3 support  int, float, bool, complex (complex) is only one integer type int, expressed as a long integer, no Python2 in Long

#!/usr/bin/python3
a, b, c, d = 20, 5.5, True, 3+5j
print(type(a), type(b), type(c), type(d))
#输出结果:<class 'int'> <class 'float'> <class 'bool'> <class 'complex'>

Isinstance also be used to determine int

#!/usr/bin/python3
a = 111
print(isinstance(a, int))
#输出结果:True

Certainly be involved in digital learning Python expression operators

数学操作:+,-,*,/,%;

按位操作:&,|,~,^(异或);

移位运算:>>, <<;

比较操作:==,!=

Python特有的逻辑运算符
逻辑运算:or,not,and;
身份测试: is,is not
序列成员关系测试:in, is not in
生成匿名函数:lambdaargs:expression

 

 

 

 

Published 35 original articles · won praise 16 · views 190 000 +

Guess you like

Origin blog.csdn.net/qq_38795430/article/details/97612270