पढ़ा है क्या PEP8 टिप्पणियों के विषय पर कहना चाहता है के बावजूद में कोड की एकल तर्ज पर लांग टिप्पणियाँ, मैं अभी भी अजगर में कोड की एकल लाइनों टिप्पणी करने के लिए कैसे सबसे अच्छा आश्चर्य है।अजगर
x = x + 1 # Compensate for border
लेकिन अगर लाइन या टिप्पणी है लंबे समय तक बातें और अधिक कठिन मिलता है: जब प्रश्न में कोड की पंक्ति (बहुत) कम है
उदाहरण दिया ठीक है। उदाहरण के लिए:
import numpy as np
import matplotlib.pyplot as plt
a = np.random.random([3, 3])
b = np.random.random([3, 3])
coords = zip(a.ravel(), b.ravel()) # match elements of a with elements of b ignoring shape
plt.scatter(*zip(*coords))
टिप्पणी काफी लंबी है, और कोड की रेखा भी है, जो पूरी चीज स्वीकार्य रेखा लंबाई से अधिक लंबी बनाती है।
मैं आमतौर पर रेखा से ऊपर टिप्पणी डाल दिया, लेकिन यह तो स्पष्ट नहीं है टिप्पणी plt
लाइन या नहीं पर लागू होता है या नहीं:
# match elements of a with elements of b ignoring shape
coords = zip(a.ravel(), b.ravel())
plt.scatter(*zip(*coords))
मैं दो लाइनों के बीच एक नई पंक्ति डालने से यह चारों ओर पाने के लिए करते हैं :
# match elements of a with elements of b ignoring shape
coords = zip(a.ravel(), b.ravel())
plt.scatter(*zip(*coords))
मैं भी इस किया है, लेकिन यह हद से ज़्यादा एक सा लगता है:
"""
match elements of a with elements
of b ignoring shape
"""
# ================================
coords = zip(a.ravel(), b.ravel())
# ================================
plt.scatter(*zip(*coords))
क्या ऐसा करने का एक स्वीकार्य तरीका है?
मैं विधि के docstring में एल्गोरिथ्म खुद का विवरण डाल दिया। –
https://www.youtube.com/watch?v=wf-BqAjZb8M – hyades
पढ़ें [पीईपी-8] (https://www.python.org/dev/peps/pep-0008/#comments) टिप्पणियों पर और [कोड लेआउट] (https://www.python.org/dev/peps/pep-0008/#code-lay-out)। –