整数,浮点,字符;
Python 还有 复数概念 :complex :a=4+0.10j ; b=6+0.16j
对于复数也有基本的加减乘等操作
x=714
print(x)
print(type(x))
y=10.26
print(y)
print(type(y))
输出结果:
714
<class 'int'>
10.26
<class 'float'>
字符串:
注意字符串的定义赋值需要双引号或者单引号(""/'')注意是英文状态下的。
由于单双引号容易被认为是字符串的引用,因此,当字符串中有单引号或是双引号时需要将"\"作为转义符,便于计算机编译正确。
str = "Hello,World;hello,Python!"
print("The value of this string is ",str)
输出:
The value of this string is Hello,world;hello,Python!
字符串的截取(切片)
str="0123456789"
print(str[0]) #输出下标为0的字符
print(str[0:4]) #输出下标0到4的字符,注意:包前不包后
print(str[0:8:2]) #三个参数的切片分别表示开始结束下标和步长
print(str[-5:-2])
输出结果:
0
0123
0246
567
分别对应 以下标单个切片,从头(默认)段切片,隔段切片,从尾切片