码迷,mamicode.com
首页 > 其他好文 > 详细

COMP9021--6.13

时间:2019-06-15 15:23:32      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:一次循环   tween   ever   rem   between   pop   ret   from   tle   

1. break语句和continue语句都可以在循环中使用,且常与选择结构结合使用,以达到在特定条件满足时跳出循环的作用。break语句被执行,可以使整个循环提前结束。而continue语句的作用是结束本次循环,回到循环的最开始然后进入下一次循环

2. ValueError

try...except ValueError

or: raise ValuError, to make a special input get the same output with the one will raise the ValueError

3. dir(str) can get all method about str, if you type 10 for example, you will get all the methods related to int

 4. str.lower() 将所有大写字母转换成小写

5. help(str.istitle) can help you know about the function

6. istitle() 方法检测字符串中每开始出现小写字母时前面是否跟着一个大写字母,Sir007James将返回True

7. set() to creat an empty set, {2,2} willl get {2}

8. 在一个function中,we can return 2 things and they will be seen in a (), otherwise we can give them names while using them to make it more clear

9. import random

random.choice(seq)返回一个列表,元组或字符串的随机项,其原理是随机选择一个位置因此我们不能使用set

10. 如果不想像9那样引入,可以写成from random import choice, later we can use choice directly

11. we may use from random import*, which can get everything from random, but which is not clear enough

12. remove is to find the beginning and scan to the end and move it, so which is not too efficienet, that is why we can use pop

13. randrange(n) can get a number between 0 and n

14. 在设置默认值参数时,默认值参数必须出现在函数形参列表的最右侧,且任何一个默认值参数右边都不能再出现非默认值参数

COMP9021--6.13

标签:一次循环   tween   ever   rem   between   pop   ret   from   tle   

原文地址:https://www.cnblogs.com/eleni/p/11027345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!