Python syntax

Python Syntax

  1. 格式化输出 – format 函数的使用

    Python format 格式化函数 | runoob

    Python format 函数的详细用法 | cnblogs

    (C++ Syntax:printf 详解 | CSDN

  2. 别名,浅拷贝与深拷贝:

    Using equal sign & function argument pass between mutable objects creates aliases.

    Shallow copy creates a copy of a list, not just a shared pointer, but only at the top level of the list.

    But if we change an element in one of the sub-structures, they are shared!

    Unless your elements are not mutable, then this is not a problem.

shallowcopy.png

Usedeepcopy when your list might have mutable elements to ensure every structure at every level is copied

deepcopy.png

  1. 函数的参数

    In the function definition, default parameters must go at the end.

    Positional arguments shall precede keyword arguments to locate themselves.

  2. 原码,反码,补码:原码、反码、补码 – 知乎

  3. try & except & else & finally & raise & assertion: 见 SI 100B Lecture 09 page 45-47

    try:
       # some code
    except:
       # do this if some error occurred
       # maybe print("Error!")
       # or you can raise Errortype("Some error information")
       # Errortype can be TypeError,NameError,etc.
    else:
    # do this if no error occurred
       # maybe print("Success!")
    finally:
       # do this no matter what happened, even a return or break or continue was executed
    # this is another way of defensive coding:
    assert <statement that should be true>, "message if not true"
    
  4. dictionary: Assume there is no order to keys or values! Keys must be unique!

    dictionary-access.png

dictionary-access2.png

  1. Dunder Methods(类似于重载运算符,指重设一些本来就存在的函数使其具有新的意义)

评论

  1. Arahc
    7 天前
    2024-11-14 20:39:44

    orz

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇