- 博客(6)
- 收藏
- 关注
原创 用python求一个数组的和与平均值
# coding = GBKa =[1,2,3,4,5]sum=0b = len(a)print("这个数组的长度为:",b)for i in a: sum =sum +iprint("这个数组之和为:",sum)print("这个数组平均数为",sum/b)
2018-04-25 15:10:10
26770
1
原创 python中编码格式问题
SyntaxError: Non-UTF-8 code starting with '\xd5' in file ex35.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details遇到此情况,加一段代码: # coding = GBK在pycharm中 是因为File--...
2018-04-25 15:06:00
534
原创 while循环::
while循环::i = 0number = []while i < 6: print("Now the i is %d" % i) number.append(i) i = i + 1 print("nuber now:", number) print("haha,i now is %d" % i)print("the number:")f...
2018-03-28 17:30:44
487
原创 python 中 打印输出 换行
中间添加 print('')即可 #对字典遍历a =['banana','apple','mango']for b in a: print(b)print('')#range函数 循环次数 默认在0开始for i in range(5):
2018-01-19 15:03:42
56564
1
原创 python 中if和elif的区别
如果程序中判断事件很多,全部用if的话,会遍历整个程序, 用elif 程序运行时,只要if或后续某一个elif之一满足逻辑值为True,则程序执行完对应输出语句后自动结束该轮if-elif(即不会再去冗余地执行后续的elif或else)。 提高效率例子:a = 88if a >= 90: print("优秀")elif a >=80: print("良好")elif a
2018-01-19 14:35:39
37781
原创 python3 中的raw_input() 和input
python3将raw_input和input进行了整合,只有inputprint("How old are you?"),age = input()print ("so %s old" %age )
2018-01-17 14:34:09
29776
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人