COMP9021--6.13

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. 在设置默认值参数时,默认值参数必须出现在函数形参列表的最右侧,且任何一个默认值参数右边都不能再出现非默认值参数

转载于:https://www.cnblogs.com/eleni/p/11027345.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值