What is DocStringIn software engineering, in fact, the part of the code is very small, mostly other things, such as writing documents. Documentation is a tool for communication.In Python, the comparison is respected in the code to write documents, code is the document, more convenient, easy to maintain, intuitive, consistent.After the code is written, the document is out. In fact, Markdown is similar to this idea, the text is finished, typesetting has
1 native Doxygen documentation support for Python annotationsBy default, Doxygen can support both styles of Python annotations, native docstring, and Java doc-like # #. But the actual use is not perfect"" @package docstringdocumentation for the This module. More details. "" " def func (): "" " documentation for a function. More details. "" " PassJava doc
Os:windows 10 Chinese version, python:3.6.4The document string (docstring) in Python appears in the first row of modules, functions, classes , and is used to describe these programs. It is ignored at execution time, but willis stored in the __doc__ property of the module, function, and class by the compiler. However, not every module, function, class has a docume
To further standardize PythonCodeTo improve readability and maintainability, it is decided to add docstring to the module, class, and function as much as possible.In my spare time, I wrote a sublime text 2 plugin. You can set the shortcut key or context menu to automatically generate docstring, which reduces the number of words on the keyboard and makes it more standard.The automatically generated
This article mainly introduces the implementation of docstring annotations in the python annotation class, which involves the access skills of python class annotations and is very useful, for more information about how to implement docstring annotations in the python program
insert Docstrings fromModules(y/N) [N]:y>doctest:automatically test code snippetsinchdoctest Blocks(y/N) [N]:N>Intersphinx:link betweenSphinxdocumentation of different projects(y/N) [N]:y>Todo:Write"Todo"entries that can shownorHidden on Build(y/N) [N]:N>Coverage:Checks forDocumentation Coverage(y/N) [N]:N>Pngmath:include math,rendered asPNG Images(y/N) [N]:N>Jsmath:include math,renderedinchThe browser byJsmath (y/N) [N]:N>ifconfig:conditional inclusion of content based on config values(y/N) [N
In Python, we typically use docstring to add string explanatory documents under Modules, classes, and functions, making it better for developers to understand what this code does. However, write so many comments, we want a document how to do, the first method can not write the comments directly CTRL + C CTRL + V, at this time Sphinx appeared, solve the problem.To use it, you need to install it first, and in
Python log format output and time format, python log time format
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s","%Y%b%d-%H:%M:%S")
The above % Y and so on are time formats, so to understand the above, Let's first look at the
One,%, or format1,%, Format Imperial PKThe format string in Python currently has two camps:% and format, which one should we choose?Since Python2.6 introduced the format-formatted string method, I think the% or format is not a pro
Python-code encoding format conversion and python encoding format conversion
Recently, I just changed my job. I didn't have much time to sort out my work. I spent most of my time familiarizing myself with the new company's business and their code framework, the most important thing is that there are still many new thin
.
"" "Return a foobarOptional Plotz says to frobnicate the Bizbaz first." " "" " oneline docstring " ""Naming conventions
Avoid using lowercase letters l(L) , uppercase letters, O(o) or I(i) separate names as a variable to differentiate between numbers 1 and0
Packages and modules use all lowercase names and try not to use underscores
The class name uses CamelCase a naming style, and the inner class can start with an underscore
Python format output (color), python format
Introduction:
If you want to display the output color in Python, it is quite easy to implement. You need termcolor knowledge!
Reference: https://pypi.python.org/pypi/termcolor/1.1.0
Enable:
Shell> pip install termcolor # If this mo
Python format function, python string format
1. The format can accept infinite parameters, and the positions can be unordered:
In [1]: "{}{}". format ("hello", "world") # do not set the location, In the default order Out [1]: 'Hel
Format the python string and format the python string.
Most of the time, when printing input content, we want a simple format instead of splicing.
General Practice:
1 name = input("name:").strip()2 age = input("age:").strip()3 job = input("job:").strip()4 print("Name:" + nam
Legacy formatting:%s,%d1. Fill in the formatted content sequentiallys = "Hello%s, hello%d"% ("World", "page") print (s)Result: ' Hello World, hello 100 '2. Use keyword parameterss= "% (name) s age% (age) d"%{"name": "Tom", "Age": 10}Print (s)Result: Tom name 10Commonly used formatting symbols%s corresponds to string type (str)%d (int) corresponding to the decimal integer type%f corresponding floating-point number (float)%r corresponding string (repr)Using the
A detailed description of string formatting str. format in Python, pythonstr. format
Preface
Python 2.6 adds a new string formatting method:str.format(). Its basic syntax is to replace the previous % through {} And ..
Placeholder syntax during formatting:
replacement_field ::= "{" [field_name] ["!" conversion] [":" for
This example describes the Python common format string method. Share to everyone for your reference, specific as follows:
The "way One" percent sign (%) way, the Class C of printf, needs to be different types respectively.
1, anonymous tuple. (Recommended for fewer parameters)
>>> ' Name:%s, age:%d '% (' Walker ', ')
' name: Walker, Age: 99 '
2, named Dict, the dictionary key can be reused.
In Python, format is used to format strings.Syntax
It uses {} And: to replace %. "Ing" ExamplePass location
In [1]: '{0},{1}'.format('kzc',18) Out[1]: 'kzc,18'In [2]: '{},{}'.format('kzc',18) Out[2]: 'kzc,18'In [3]: '{1},{0},{1}'.format
In Python, format is used to format strings.
Syntax
It uses {} And: to replace %."Ing" Example
Pass location
In [1]: '{0},{1}'.format('kzc',18) Out[1]: 'kzc,18'In [2]: '{},{}'.format('kzc',18) Out[2]: 'kzc,18'In [3]: '{1},{0},{1}'.format
characters into the next variable in the parameter list
Use of basic methods: 1 #!/usr/bin/python 2 #coding =utf-8 3 "4 You can specify the alignment of the desired length of the string: 5 #!/usr/bin/python#coding=utf-8# use the ' {} ' placeholder print (' I\ ' m {},{} ') using the Str.format () function #. Format (' Hongten ', ' Welcome to my space!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.