- order順序:
name = "Alice"
age = 25
formatted_string = "My name is {}, and I'm {} years old.".format(name, age)
print(formatted_string)輸出:

在格式化字符串中使用占位符 {},按照传递给.format()方法的参数顺序依次替换占位符。
- keyword關鍵字
name = "Bob"
age = 30
formatted_string = "My name is {name}, and I'm {age} years old.".format(name=name, age=age)
print(formatted_string)輸出:

在格式化字符串中使用命名的占位符 {name} 和 {age},并使用关键字参数 name=name 和 age=age 来指定要替换的值。
.format(name=name, age=age)
使用關鍵字不要忘記
name=name, age=age
(賦值給關鍵字)
順序不需要
3. index 索引方法
name = "Charlie"
age = 35
formatted_string = "My name is {0}, and I'm {1} years old.".format(name, age)
print(formatted_string)輸出:

推薦hahow線上學習python: https://igrape.net/30afN
使用順序

:.2%表示将数值格式化为百分比形式,并保留两位小数。
使用關鍵字:

前綴f:

推薦hahow線上學習python: https://igrape.net/30afN





![Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()] Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()]](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2024/11/20241123194900_0_5218de.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言