help() Function in Python – dir() Function जिन Callable Methods की List Return करता है, वे क्या Action Perform करते हैं, इस बात का पता लगाने के लिए हम Python के help() Function को Use कर सकते हैं और जिस भी String Method की Working के बारे में हमें जानना होता है, उसे इस help() Function में निम्न Example Program के अनुसार Parameter की तरह Pass कर देते हैं-
[code] FileName: helpFunction.py str = "MADAN MOHAN" # Retrieve Help for ljust() Method Supported by str print(help(str.ljust)) Output Help on built-in function ljust: ljust(...) method of builtins.str instance S.ljust(width[, fillchar]) -> str Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space). None [/code]
जब हम किसी Method का Help Description प्राप्त करना चाहते हैं, तब हमें उस Method को उसके Associated Object के साथ ही Specify करना होता है, इसीलिए इस Example में सबसे पहले हमने एक String Object str Create किया है और फिर उस String Object के साथ उस Method के नाम को Specify किया है, जिसका Help Description हमें Output के रूप में चाहिए।
चूंकि, हमें केवल ljust Method का Description चाहिए, इसीलिए हमने इसे बिना Trailing Parenthesis के str.ljust लिखा है, यदि हम इसे Trailing Parenthesis के साथ str.ljust() लिख देते, तो Python इस Method को Execute करके Generate होने वाले Result को Return करने का प्रयास करता, न कि इसकी Help Description को।
help() एक बहुत ही Simple Interface है जिसे Python के PyDoc के साथ Ship किया जाता है। ये help() Function एक ऐसा Tool है जो कि किसी Object से उसके Documentation को Extract करने का काम करता है। हम इस Documentation को HTML Format में भी Render कर सकते हैं और इस HTML Documentation को Web Browser के माध्यम से भी देख सकते हैं।
जरूरी नहीं है कि हम किसी String Object के Attribute का ही Help Documentation Access करें, बल्कि हम किसी Simple String जैसे कि help(“KRISHNA”) का भी Documentation Return कर सकते हैं। लेकिन इस तरह के String का कोई उपयुक्त Help Return नहीं होता, इसलिए हमेंशा किसी Method के लिए ही help() Function को Use करना चाहिए।
dir() व help() दोनों Functions Parameter के रूप में किसी Real Object या किसी Data Type जैसे कि str, list और dict का Name Accept करते हैं। जब हम किसी Data Type का Name Parameter के रूप में Pass करते हैं, तब help() function हमें वही Attributes की List Return करता है, जो Real Object को Parameter के रूप में Pass करने पर Return करता है। साथ ही हमें Type Name के माध्यम से किसी Specific Method के बारे में Help प्राप्त करने की सुविधा भी देता है।
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook Python in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी है, तो निश्चित रूप से ये EBook भी आपके लिए काफी उपयोगी साबित होगी।
Python in Hindi | Page: 602 | Format: PDF