1. 函数简化
「小白」:
def add(a, b): sum = a + b return sum
「高手」:
def add(a, b): return a + b
2. 注释
「小白」:
#注1 #注2
「高手」:
''' 注1 注2 '''
3. 遍历
「小白」:
squared_numbers = [] for i in range(10): squared_numbers.append(i ** 2)
「高手」:
squared_numbers = [i ** 2 for i in range(10)]
4.字符串处理
「小白」:
def print_hello(name): print("Hello, " + name) print_hello("Alice") print_hello("Bob")
「高手」:
def print_hello(name): print(f"Hello, {name}") print_hello("Alice") print_hello("Bob")
5. 异常处理
「小白」:
def calculate_discount(price, discount): return price * (1 - discount / 100)
「高手」:
def calculate_discount(price, discount): assert 0 <= discount <= 100, "Discount must be between 0 and 100" return price * (1 - discount / 100)
为了帮助大家更好的学习网络安全,我给大家准备了一份网络安全入门/进阶学习资料,里面的内容都是适合零基础小白的笔记和资料,不懂编程也能听懂、看懂这些资料!
因篇幅有限,仅展示部分资料,需要点击下方链接即可前往获取
[2024最新优快云大礼包:《黑客&网络安全入门&进阶学习资源包》免费分享]
因篇幅有限,仅展示部分资料,需要点击下方链接即可前往获取
[2024最新优快云大礼包:《黑客&网络安全入门&进阶学习资源包》免费分享]