[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-682219-105":3,"detail-sidebar-cat-0-en-105":81,"doc-detail-682219-en":130,"doc-similar-682219":149},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","python-style-rules-docstring-conventions-coding-style","Python Style Rules - Docstring Conventions - Coding Style","","Python Style Rules document focusing on two core PEP references: PEP 8 for Python code style and PEP 257 for docstring conventions. It defines what module, function, class, or method docstrings should be, how they are accessed via the object’s doc attribute, and how to format multiline docstrings using triple quotes. It also specifies practical coding style standards, including 4-space indentation, avoiding mixed tabs, limiting lines to 79 characters, spacing around binary operators, and clear, non-redundant comments plus naming conventions for classes, modules, functions, and variables.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/python-style-rules-docstring-conventions-coding-style/682219/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/python-style-rules-docstring-conventions-coding-style/682219.png","ImageObject",300,407,{"name":42,"@type":43},"Adam","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-26","2026-11-06",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",6,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"What are PEP 8 and PEP 257 used for in this style guide?","Question",{"text":63,"@type":64},"PEP 8 covers style for Python code, while PEP 257 defines conventions for docstrings.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How should multiline docstrings be formatted?",{"text":68,"@type":64},"Use triple quotes around the literal; the closing triple quote of a multiline docstring should be on its own line and preferably preceded by a blank line.",{"name":70,"@type":61,"acceptedAnswer":71},"What are the key coding style rules for indentation and line length?",{"text":72,"@type":64},"Use 4 spaces per indentation level, never mix tabs and spaces, and keep maximum line length to 79 characters.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},682219,1793963012,{"code":4,"msg":82,"data":83},"success",[84,88,92,96,101,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":85,"show_sort_weight":86,"slug":87},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":89,"show_sort_weight":90,"slug":91},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":93,"show_sort_weight":94,"slug":95},"Exam",70,"exam",{"id":97,"doc_module":4,"doc_module_name":25,"category_name":98,"show_sort_weight":99,"slug":100},5,"Comic",60,"comic",{"id":55,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":97,"slug":129},19,"General","general",{"code":4,"msg":82,"data":131},{"doc_id":79,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":55,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":115,"language":139,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":12,"update_tm":80,"read_time":143,"preview_page_count":22,"preview_urls":144},1374404737137,"https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d","Python Style Rules  \n● Two PEPs (Python Enhancement Proposals) you should be familiar with:  \n– PEP 8 – Style Guide for Python Code  \n– PEP 257 – Docstring Conventions  \nDocstring Conventions  \n● A string literal for documenting a module, function, class, or method.  \n● Such string literals are accessible as the  doc  attribute of the object  \nDocstring Conventions  \n● Use triple quotes to surround the literal:  \n● A triple quote that ends a multiline docstring should be on a line by itself, and preferably preceded by a blank line  \ndef blah(a,b):  \n“””Does something with a,b.“””  \ndef bar(a,b):  \n“””Does something really complex with a and b, and then returns a new value .  \n“””  \nDocstring Conventions  \n● Your docstrings should be informative and tell the reader what the module/function/etc. does.  \n● E.g. for a function docstring, do not simply reiterate the function signature, or for a class docstring, do not say “this is a class of type \u003Cclassname>”.  \nCoding Style  \n● 4 spaces per indentation level  \n● Never mix tabs and spaces (and preferably use only spaces)  \n● Max line length: 79 characters  \n● Top level functions separated from class definitions by 2 blank lines  \n● Methods in a class separated by a single blank line  \nCoding Style  \n● Surround binary operators by a single space  \n– e.g. (“x + y” not “x+y”) .  \nCoding Style  \n● Comments should not contradict the code, and should be complete sentences.  \n● Use inline comments sparingly, and never use them when they state the obvious  \nCoding Style  \n● Class names should begin with a capital, and each distinct word in a class name should be capitalized. (e.g. class FileMonitor )  \n● Module names, function names, and variable names should be lower case with words separated by underscores (e.g. def do_something())  \nCoding Style  \n● Python doesn't have public/protected/private modifiers like in Java.  \n● Instead, you can use the convention that a class attribute that begins with an underscore is private (e.g. _myvar ) .  \n● Technically, it can be accessed, but you shouldn't.","cbCaitTJFfU8sxam","https://ap.wps.com/l/cbCaitTJFfU8sxam","pdf",236764,"English","# Docstring Conventions\n## What docstrings are\n## Multiline formatting with triple quotes\n# Coding Style\n## Indentation, line length, blank lines\n## Operator spacing and comments\n## Naming conventions and privacy convention","[{\"question\":\"What are PEP 8 and PEP 257 used for in this style guide?\",\"answer\":\"PEP 8 covers style for Python code, while PEP 257 defines conventions for docstrings.\"},{\"question\":\"How should multiline docstrings be formatted?\",\"answer\":\"Use triple quotes around the literal; the closing triple quote of a multiline docstring should be on its own line and preferably preceded by a blank line.\"},{\"question\":\"What are the key coding style rules for indentation and line length?\",\"answer\":\"Use 4 spaces per indentation level, never mix tabs and spaces, and keep maximum line length to 79 characters.\"}]","Python Style Rules - Docstring Conventions - Coding Style | PDF",23,[145],{"page_no":22,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-06/9a958521ff25fd3bb91af4d39f473cb3.webp",983,736,{"list":150,"token":11},[151,157,163,169,175,181,187,193,200,206],{"doc_id":152,"doc_title":153,"file_type":137,"home_preview_img_url":154,"slug":155,"view_count":55,"category_name":29,"create_tm":156},682223,"Python PEP8 style guide - Cheat Sheet - Naming conventions - Maximum Line Length and Line Breaking - Indentation - Comments - Code Layout","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999427735/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=fUTp1vWMj2xF%2FDpZCckPhjjDHgg%3D","python-pep8-style-guide-cheat-sheet-naming-conventions-maximum-line-length-and-line-breaking-indentation-comments-code-layout",1793963021,{"doc_id":158,"doc_title":159,"file_type":137,"home_preview_img_url":160,"slug":161,"view_count":97,"category_name":29,"create_tm":162},692315,"Good Coding Practices - Python Code Best Practices","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230002739157/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=dIK7fGWUSs3W7iZJ37yw9bjvzs0%3D","good-coding-practices-python-code-best-practices",1794193122,{"doc_id":164,"doc_title":165,"file_type":137,"home_preview_img_url":166,"slug":167,"view_count":105,"category_name":29,"create_tm":168},692314,"CS 116 Course Specific Style Guide - Document","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230003205286/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=mOoBkOvfd6THaIXy2UNOZWiw2G8%3D","cs-116-course-specific-style-guide-document",1794193120,{"doc_id":170,"doc_title":171,"file_type":137,"home_preview_img_url":172,"slug":173,"view_count":97,"category_name":29,"create_tm":174},682224,"Python PEP8 - The Style Guide for Python Code","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999427682/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=eNdpda5LBdROyDtjPWvL22MJIlU%3D","python-pep8-the-style-guide-for-python-code",1793963024,{"doc_id":176,"doc_title":177,"file_type":137,"home_preview_img_url":178,"slug":179,"view_count":30,"category_name":29,"create_tm":180},682216,"Python Code Style Guide - Introduction - Format and use of White Space","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999427657/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=RtmRne64D4V4WQDBkN9WxYqa1kg%3D","python-code-style-guide-introduction-format-and-use-of-white-space",1793963005,{"doc_id":182,"doc_title":183,"file_type":137,"home_preview_img_url":184,"slug":185,"view_count":33,"category_name":29,"create_tm":186},692325,"Python Coding Standards - Version A - Released","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230003217830/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=Ld6CrPDBYvNVE2pcqUPhAC5ia8g%3D","python-coding-standards-version-a-released",1794193583,{"doc_id":188,"doc_title":189,"file_type":137,"home_preview_img_url":190,"slug":191,"view_count":55,"category_name":29,"create_tm":192},682220,"Style Guide for CS 231 and CS 234 - Python Style Requirements","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229998448640/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=o5EouvTNs4UP7RCXmkOrR3LeKQw%3D","style-guide-for-cs-231-and-cs-234-python-style-requirements",1793963013,{"doc_id":194,"doc_title":195,"file_type":137,"home_preview_img_url":196,"slug":197,"view_count":198,"category_name":29,"create_tm":199},391232,"Python Interview Questions - List vs Tuples - Key Features","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229917654344/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=APf1Avtr7TJWO5jCHB6WgqdRLhg%3D","python-interview-questions-list-vs-tuples-key-features",15,1790350253,{"doc_id":201,"doc_title":202,"file_type":137,"home_preview_img_url":203,"slug":204,"view_count":123,"category_name":29,"create_tm":205},692230,"Python Handbook - Updated October 14, 2026","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230003011060/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=qu0ViJZb44oXG0wVcyCMRhK97Z0%3D","python-handbook-updated-october-14-2026",1794186375,{"doc_id":207,"doc_title":208,"file_type":137,"home_preview_img_url":209,"slug":210,"view_count":33,"category_name":29,"create_tm":211},682217,"A Python Style Guide - Draft","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229998448576/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=AchyGnudPOSoWgVwFuUaOtWGuMY%3D","a-python-style-guide-draft",1793963006]