This question already has an answer here:
Hi I am recently studying a book that describes the data science from scratch. Then I found something like this :
A = [[1,2,3],[4,5,6]]
def shape(A) :
num_rows = len(A)
num_cols = len(A[0]) if A else 0
return num_rows, num_cols
I do not understand the part 'if A else 0'. I used to think that the if statement contains condition.. Could that possibly mean 'if the elements of A exist then return len(A[0]), else then return 0'? I am not quite sure. Please help. Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire