खोज…


सामान्य सहायता प्राप्त करना

यदि help फ़ंक्शन को कंसोल में बिना किसी तर्क के कहा जाता है, तो पायथन एक इंटरैक्टिव मदद कंसोल प्रस्तुत करता है, जहां आप पायथन मॉड्यूल, प्रतीकों, कीवर्ड और बहुत कुछ के बारे में पता लगा सकते हैं।

>>> help()

Welcome to Python 3.4's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.4/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

अंतिम अभिव्यक्ति का जिक्र

कंसोल में अपनी अंतिम अभिव्यक्ति से अंतिम परिणाम का मूल्य प्राप्त करने के लिए, एक अंडरस्कोर _ उपयोग करें।

>>> 2 + 2
4
>>> _
4
>>> _ + 6
10

यह जादू अंडरस्कोर मान केवल एक अजगर अभिव्यक्ति का उपयोग करते समय अद्यतन किया जाता है जिसके परिणामस्वरूप मूल्य होता है। फ़ंक्शंस को परिभाषित करना या लूप के लिए मान नहीं बदलता है। यदि अभिव्यक्ति एक अपवाद उठाती है तो _ कोई परिवर्तन नहीं होगा।

>>> "Hello, {0}".format("World")
'Hello, World'
>>> _
'Hello, World'
>>> def wontchangethings():
...     pass
>>> _
'Hello, World'
>>> 27 / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>> _
'Hello, World'

याद रखें, यह मैजिक वैरिएबल केवल इंटरएक्टिव पाइथन इंटरप्रेटर में उपलब्ध है। रनिंग स्क्रिप्ट्स ऐसा नहीं करेंगी।

पायथन कंसोल को खोलना

अजगर के प्राथमिक संस्करण के लिए सांत्वना आमतौर पर टाइप करके खोला जा सकता है py अपने विंडोज़ कंसोल या में python दूसरे प्लेटफार्म पर।

$ py
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

आप एक से अधिक संस्करण है, तो डिफ़ॉल्ट रूप से उनके निष्पादनयोग्य पर मैप किए जाएँगे python2 या python3 क्रमशः।

यह निश्चित रूप से आपके पैठ में होने वाले पायथन निष्पादनों पर निर्भर करता है।

PYTHONSTARTUP चर

आप पायथन के कंसोल के लिए PYTHONSTARTUP नामक एक पर्यावरण चर सेट कर सकते हैं। जब भी आप पायथन कंसोल में प्रवेश करते हैं, तो यह फ़ाइल निष्पादित हो जाएगी, जिससे आप कंसोल में अतिरिक्त कार्यक्षमता जोड़ सकते हैं जैसे कि आमतौर पर उपयोग किए गए मॉड्यूल को स्वचालित रूप से आयात करना।

यदि PYTHONSTARTUP चर को इस फ़ाइल में स्थान पर सेट किया गया था:

print("Welcome!")

फिर पायथन कंसोल को खोलने से इस अतिरिक्त आउटपुट में परिणाम मिलेगा:

$ py
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Welcome!
>>>    

कमांड लाइन तर्क

पाइथन में कई तरह के कमांड-लाइन स्विच हैं, जिन्हें py को पास किया जा सकता है। ये पाई- py --help प्रदर्शन करके पाया जा सकता है, जो पायथन 3.4 पर यह आउटपुट देता है:

Python Launcher

usage: py [ launcher-arguments ] [ python-arguments ] script [ script-arguments ]

Launcher arguments:

-2     : Launch the latest Python 2.x version
-3     : Launch the latest Python 3.x version
-X.Y   : Launch the specified Python version
-X.Y-32: Launch the specified 32bit Python version

The following help text is from Python:

usage: G:\Python34\python.exe [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-b     : issue warnings about str(bytes_instance), str(bytearray_instance)
         and comparing bytes/bytearray with str. (-bb: issue errors)
-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser; also PYTHONDEBUG=x
-E     : ignore PYTHON* environment variables (such as PYTHONPATH)
-h     : print this help message and exit (also --help)
-i     : inspect interactively after running script; forces a prompt even
         if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I     : isolate Python from the user's environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO    : remove doc-strings in addition to the -O optimizations
-q     : don't print version and copyright messages on interactive startup
-s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S     : don't imply 'import site' on initialization
-u     : unbuffered binary stdout and stderr, stdin always buffered;
         also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
-v     : verbose (trace import statements); also PYTHONVERBOSE=x
         can be supplied multiple times to increase verbosity
-V     : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
         also PYTHONWARNINGS=arg
-x     : skip first line of source, allowing use of non-Unix forms of #!cmd
-X opt : set implementation-specific option
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ';'-separated list of directories prefixed to the
               default module search path.  The result is sys.path.
PYTHONHOME   : alternate <prefix> directory (or <prefix>;<exec_prefix>).
               The default module search path uses <prefix>\lib.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.
PYTHONHASHSEED: if this variable is set to 'random', a random value is used
   to seed the hashes of str, bytes and datetime objects.  It can also be
   set to an integer in the range [0,4294967295] to get hash values with a
   predictable seed.

किसी वस्तु के बारे में सहायता प्राप्त करना

पायथन कंसोल एक नया फ़ंक्शन, help जोड़ता है, जिसका उपयोग किसी फ़ंक्शन या ऑब्जेक्ट के बारे में जानकारी प्राप्त करने के लिए किया जा सकता है।

किसी फ़ंक्शन के लिए, help अपने हस्ताक्षर (तर्क) और उसके डॉकस्ट्रिंग help प्रिंट करती है, यदि फ़ंक्शन में एक है।

>>> help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.

किसी ऑब्जेक्ट के लिए, ऑब्जेक्ट की डॉकस्ट्रिंग और अलग-अलग सदस्य फ़ंक्शंस help सूचीबद्ध करने में help करता है।

>>> x = 2
>>> help(x)
Help on int object:

class int(object)
 |  int(x=0) -> integer
 |  int(x, base=10) -> integer
 |
 |  Convert a number or string to an integer, or return 0 if no arguments
 |  are given.  If x is a number, return x.__int__().  For floating point
 |  numbers, this truncates towards zero.
 |
 |  If x is not a number or if base is given, then x must be a string,
 |  bytes, or bytearray instance representing an integer literal in the
 |  given base.  The literal can be preceded by '+' or '-' and be surrounded
 |  by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
 |  Base 0 means to interpret the base from the string as an integer literal.
 |  >>> int('0b100', base=0)
 |  4
 |
 |  Methods defined here:
 |
 |  __abs__(self, /)
 |      abs(self)
 |
 |  __add__(self, value, /)
 |      Return self+value...


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow