本文目錄一覽:
Python疑問?
`for…in…` 是 python 的循環結構
range(start, end, step) 是 python 內置的生成器,用於生成從 start 到 end 步長為 step的序列
`for…in…` 可以迭代任何有效的 python 可迭代對象,包括但不限於:字符串,列表,元組,字典,集合。
操作示例
“`python
aString = ‘hello world’
for c in aString:
doSomething(c)
“`
關於python(while和prompt)的疑問?
while循環判斷條件先走,提示輸入時循環處於中斷狀態,輸入「quit」後,賦值給message,下一句print打印出message的值。繼續走while循環,此時message已經等於quit了,所以結束循環退出程序。
python初學編程疑問
輸入python new.py命令是在命令行下,而不是進入到python的shell里,我看你前面的應該是進入到shell里了。在python的shell里不能直接運行py文件,但是能夠直接import py文件,即import用戶模塊。
還有,建議你為python配置一下環境變量,這樣就不需要進入到python的安裝目錄去執行python命令了。
另外如果你用的是python3,print 『hello, world’就是錯誤的語法,不過應該不是提示你圖裡的錯誤。
python代碼bug求解
錯誤在於下一次迭代時,n會變成下一個奇數5,
而18行的代碼通過傳遞參數n鎖定了n值
可以通過輸出一些log查看:
以下代碼通過把lambda展開成普通函數,並輸出調用filter函數的參數來查看,比較一下就能明白了。
def _not_divisible(n):
def func(x):
print(“!!!!!!!!!!!!!”)
print(x, n)
return x % n 0
return func
def primes():
yield 2
print(1111)
it = _odd_iter()
while True:
n = next(it)
print(2222)
yield n
def func(x):
print(“!!!!!!!!!!!!!”)
print(x, n)
return x % n 0
it = filter(func, it)
#it = filter(_not_divisible(n), it)
關於python代碼的問題
get_shape()是得到inputs的維度,返回的是一個元組(tuple)。
比如inputs是一個
1
*
1
*
2
*
3
的數組
array([[[[1, 2, 3], [4, 5, 6]]]])那麼get_shape()返回的是(
1,
1,
2,
3
)
as_list()將tuple轉換成list,(
1,
1,
2,
3
)
變成了
[
1,
1,
2,
3
]
as_list()[3]取得[1,
1,
2,
3]的第3個元素,3,也就是得到了inputs共有三列的數據
原創文章,作者:SWAUS,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/129704.html