[Python] How to fix issues with Python keyword conflicts in variable names? [closed]

Discussão em 'Python' iniciado por Stack, Abril 27, 2025.

  1. Stack

    Stack Membro Participativo

    correct_sum = []
    for i in range(1, 20): # Correct usage of range and for
    model = KNeighborsClassifier(n_neighbors=i)
    model.fit(x_train, y_train)
    pred = model.predict(x_test)
    correct = np.sum(pred == y_test)
    correct_sum.append(correct)

    print(correct_sum)


    i was typing this code block in jupyter notebook every thing is uptodate but it detects word "range" as "for" and "in", same theme color for all three words and this gives ourput like this when i call it [np.int64(25), np.int64(26), np.int64(28), np.int64(29), np.int64(28), ...] but i want an array like this [25, 26, 28,...] Restart the kernel in Jupyter Notebook.

    Re-run the code after restartin your text the kernel.

    Clear output: Sometimes, output errors or old code can mess with the current session.

    Continue reading...

Compartilhe esta Página