程式碼:
a = 1
lsta = list(a)
print(lsta,type(lsta),len(lsta))
輸出:
Traceback (most recent call last):
File “C:\Python\Radar_20221005\untitled1.py”, line 3, in <module>
lsta = list(a)
TypeError: ‘int’ object is not iterable
int無法取list()
如果取array()呢?
程式碼:
import numpy as np
a = 1
arya = np.array(a)
print(arya, type(arya), len(arya))
輸出:
Traceback (most recent call last):
File “C:\Python\Radar_20221005\untitled1.py”, line 7, in <module>
print(arya,type(arya),len(arya))
TypeError: len() of unsized object
int可以取array(),
只是長度0 (不要誤會長度1)
所以取len()時錯誤
empty list: []長度也是0
去掉len()

3(1+2)的左右邊沒有[ ] 包覆
type為ndarray (0-dimensional)
用法同int
numpy官網:

2D array的運算:

推薦hahow線上學習python: https://igrape.net/30afN
![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://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)









近期留言