145.python介绍(二)
python用作计算器时,可直接输入算式计算:
math库调入可以引入许多数学上的函数
import math #math库 math.pi math.cos(math.pi/2) math.floor(9.2) #取整函数应用题
#小姐姐去买水果,苹果单价5元一斤,葡萄单价15元一斤。 #小姐姐买了三斤苹果,一斤葡萄, #请问,买苹果花了多少钱,买葡萄花了多少钱?总共花了多少钱? #解法一 5*3 15*1 5*3+15*1 #解法二 apple=5 grape=15 apple_weight=input ("please input the weight of apple:") grape_weight=input ("please input the weight of grape:") apple_price=appe*apple_weight grape_price=grape*grape_weight total_cost=apple_price+grape_price print ("the price of apple is {},the price of grape is {},total cost is {}.".format(apple_price,grape_price,tatal_cost))#format用于输出优化python中的变量值交换
a=1 b=2 a,b=b,a146.变量名命名规范
字母、数字、下划线,且首位不可为数字
147.代码规范
三点建议:
1.不要使用单字符的变量名;
2.变量名要清晰地表达变量的意思;
3.合理使用字母中间的下划线。
148.数值类型
变量类型:字符串(str)、数值(int/float/complex)、列表(list)、元组(tuple)、字典(dict)
#取最小值 min(1,2,3,4,5) #取最大值 max(1,2,3,4,5) #求最大值 sum([1,2,3,4,5]) #角度与弧度转换 import mathmath.radians(180) #求商取余 divmod(10,3)客服小哥哥说一个周有效,我得抓紧时间了....
转载于:https://www.cnblogs.com/kraken7/p/8425412.html
相关资源:小白入门必读 《从Python开始学编程》-高清