python无需定义变量,而更接近自然语言
a=321
b=12
print(a + b)
print(a - b)
print(a * b)
print(a / b)
a = 100
b = 12.345
c =1+5j
d='hello world'
e=True
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
变量名=类型(input(‘引导信息’))
print('占位符' % (变量))
a=int(input('a='))
b=int(input('b='))
print('%d+%d=%d' % (a,b,a+b))
print('%d-%d=%d' % (a,b,a-b))
print('%d*%d=%d' % (a,b,a*b))
print('%d/%d=%d' % (a,b,a/b))
print('%d//%d=%d' % (a,b,a//b))
print('%d %% %d=%d' % (a,b,a%b))
print('%d ** %d=%d' % (a,b,a**b))
a= 10
b= 3
a +=b #a=a+b
a *=a+2 #a=a*(a+2)
print(a)
== != > < >= <= 关系运算符
and or not 逻辑运算符
ture or flase 不用占位符,无需占位符发时候print(' ', )
flag0 = 1==1 #“==”优先级高于“=”
flag1 = 3>2
flag2 = 2<1
flag3 = flag1 and flag2
flag4 =flag1 or flag2
flag5 =not(1!=2)
print('flag0=',flag0)
print('flag1=',flag1)
print('flag2=',flag2)
print('flag3=',flag3)
print('flag4=',flag4)
print('flag5=',flag5)
print('please input the F:')
f=float(input())
c=(f-32)/1.8
print('c=%f' % c)
f = float(input('请输入华氏温度'))
c = (f-32)/1.8
print('%.1f华氏度 =%.1f摄氏度' % (f,c))
r=float(input('请输入圆的半径:'))
c=6.28*r
s=3.14*r*r
print('该圆的周长为%.2f,面积为%.2f' % (c,s))
year = int(input('请输入年份:'))
is_leap = year % 4 == 0 and year %100!=0 or \
year %400 ==0
print(is_leap)