cs61a class note(2)

本文探讨了Python中变量及函数命名的原则,并分享了如何通过合理抽象提高代码复用率和可读性的方法。强调了一个函数只做一件事的重要性,以及避免重复代码(DRY原则)的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    Lecture 2 is all about python  variable.As i have learned python programming before.There're still not  too many new things to me.
    Here are some interesting points in this lecture.

    The principle of setting names for the function
    (1)The funcion's name is better in lower case and seperated by the underscore.

    (2)The function's name is better to tell what the operation(ie. print open ...) is or what's the return value(ie. max abs ...) is .
    (3)The parameter's name is better in lower case and seperated by the underscore . But single word is more encouraged !

    (4)The parameter's name is better not use I(captive i) ,l(ell) , O(oh). Because it may confuse the numbers and the letter .
    
    Function as abstraction . After i get a funtion ,i just use it as a blackbox and am not concerned about the intent(How the funciton process the inputs )

    3/26 
since CS61A this part is all about some basic grammer about python ,I pay less attention to this lecture . But that doesn't mean that I would not want to finish this course . Here are some update . 

(1) A function should only have one operation .If a function combines several operations , it'd better be divided into serval functions .
(2) Once you find your code with several parts repeating . Remember the software engineering principle  DRY(DON'T REPEAT YOUR code) . You'd better make these repeating codes into one function . 

(3) Your function should be defined more generally . Think about the function pow & function square . We'd better define function pow , but not square .  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值