or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
string
資訊之芽 2023 Python 語法班
Author: Sean 韋詠祥
Note:
日期:2023-03-26
課程時間:14:00 - 15:20
這堂課你會學到…
什麼是字串
'
或"
包起來課程回顧:字串輸出
Note:
已學過:字串、指派變數、輸出
怎樣算一個字串
字串運算:範例
字串運算:練習
請紀錄哪些不能正常執行
又有哪些輸出結果不符預期
Note:
1a banana
1b banana
1c banabana
1d invalid syntax
2a lalaland
2b lalaland
2c invalid syntax
2d landlandland
字串比較
格式化字串
Format String
習題:九九乘法・改
https://neoj.sprout.tw/problem/3089/
跳脫字元
\n
\t
\'
,\"
'
), 雙引號("
)\\
\
)\xhh
\uhhhh
\<換行>
跳脫字元:練習
試著輸出以下文字
字串操作
取得長度 (length)
索引 (index)
迭代 (iterate)
分割 (slice)
Immutable(不可變)
如果我們想改其中一個字
字串處理
replace()
find()
split()
join()
注意用法是
'分隔符'.join([列表])
strip()
在
input()
時很常用字串處理:練習
你有另一個不打標點符號的檳友
總是用一些空白代替逗號,用 XD 代替句號
請你用 Python 幫他改成正確的標點符號
進階挑戰:一句話完成
Note:
延伸:byte literal
Note:
pwntools
Python 2
Python 3.0 在 2008 年底釋出
舊版 Python 2 在 2020 年初被正式淘汰
在 Python 2 的字串基於 byte
而 Python 3 則預設是 Unicode 字串
Unicode
在 UTF-8 編碼中,
U+D8
會變成b'\xC3\x90'
Ref: Unicode、UTF-8 差異
Byte
Week 12. pwntools
延伸:格式化字串
(有興趣自行參考 pyformat.info)
彩蛋:WTF Python
Ref: satwikkansal/wtfpython(簡中翻譯)
Not knot!
Half triple-quoted strings
Strings can be tricky sometimes
Splitsies
Character
以下這句話在語法上是正確的
因為 Python 並沒有 char 這種資料型別
對字串使用
[x]
取值,會回傳包含單個字的 string,而不是字元Thanks
投影片連結:https://hackmd.io/@Sean64/py-string
這份投影片以 創用 CC - 姓名標示 授權公眾使用,原始碼及講稿請見 此連結。