一 phython 认识
完成同样事情代码输入少
大规模使用简单易学
可以做网站及游戏后台等等
二phython变量
变量无需声明 使用前必须赋值 ‘类型’所指是变量所指的内存中对象的类型
1.变量的赋值
A.单一变量赋值
a=100
b=1000.0
c='hello'
print(a)
print(b)
print(c)
结果
100
1000.0
hello
B多个变量的赋值
a=b=c=1
或者多个对象指定多个变量
a,b,c=100,1000.0,'hello'
2.变量的数据类型及查看方法
A Number(int float bool complex)
查看;type()
判断;isinstrance
a=20
print(type(a))
<class 'int'>
a=20
istance(a,int)
True
B String(str)
3.数值运算
A(number)
5+4#加法
9
4-3#减法
1
3*7#乘法
21
3**2#乘方
9
6/5#除法(得到浮点数)
1.2
6//5#整除(得到整数)
1
6%5#除余(得到余数)
1
B(string)
str='iloveyou'
print(str)#输出字符串
iloveyou
prinf(str[0])#输出字符串第一个
i
print(str*2)#重复输出字符串两次
iloveyouiloveyou
print(str+'test')#连接字符串
iloveyoutest
4.数据类型转换(常用)
int(x)
float(x)
str(x)
chr(x)