[{"data":1,"prerenderedAt":452},["ShallowReactive",2],{"content-query-UMAnYSiqqp":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"tags":10,"body":11,"_type":446,"_id":447,"_source":448,"_file":449,"_stem":450,"_extension":451},"/tutorials/python-conventions","tutorials",false,"","Python conventions","Avoid running code in the script root.","python",{"type":12,"children":13,"toc":444},"root",[14,21,92,96,101,238,241,246,405,408,435,438],{"type":15,"tag":16,"props":17,"children":18},"element","p",{},[19],{"type":20,"value":9},"text",{"type":15,"tag":22,"props":23,"children":26},"pre",{"className":24,"code":25,"language":10,"meta":7,"style":7},"language-python shiki shiki-themes github-light monokai monokai github-light monokai","if __name__ == \"__main__\":\n    \"\"\"\n    Main function here\n    \"\"\"\n",[27],{"type":15,"tag":28,"props":29,"children":30},"code",{"__ignoreMap":7},[31,66,75,84],{"type":15,"tag":32,"props":33,"children":36},"span",{"class":34,"line":35},"line",1,[37,43,49,54,60],{"type":15,"tag":32,"props":38,"children":40},{"style":39},"--shiki-default:#D73A49;--shiki-dark-mode:#F92672;--shiki-sky-dark-mode:#F92672;--shiki-light-mode:#D73A49;--shiki-blue-mode:#F92672",[41],{"type":20,"value":42},"if",{"type":15,"tag":32,"props":44,"children":46},{"style":45},"--shiki-default:#005CC5;--shiki-dark-mode:#F8F8F2;--shiki-sky-dark-mode:#F8F8F2;--shiki-light-mode:#005CC5;--shiki-blue-mode:#F8F8F2",[47],{"type":20,"value":48}," __name__",{"type":15,"tag":32,"props":50,"children":51},{"style":39},[52],{"type":20,"value":53}," ==",{"type":15,"tag":32,"props":55,"children":57},{"style":56},"--shiki-default:#032F62;--shiki-dark-mode:#E6DB74;--shiki-sky-dark-mode:#E6DB74;--shiki-light-mode:#032F62;--shiki-blue-mode:#E6DB74",[58],{"type":20,"value":59}," \"__main__\"",{"type":15,"tag":32,"props":61,"children":63},{"style":62},"--shiki-default:#24292E;--shiki-dark-mode:#F8F8F2;--shiki-sky-dark-mode:#F8F8F2;--shiki-light-mode:#24292E;--shiki-blue-mode:#F8F8F2",[64],{"type":20,"value":65},":\n",{"type":15,"tag":32,"props":67,"children":69},{"class":34,"line":68},2,[70],{"type":15,"tag":32,"props":71,"children":72},{"style":56},[73],{"type":20,"value":74},"    \"\"\"\n",{"type":15,"tag":32,"props":76,"children":78},{"class":34,"line":77},3,[79],{"type":15,"tag":32,"props":80,"children":81},{"style":56},[82],{"type":20,"value":83},"    Main function here\n",{"type":15,"tag":32,"props":85,"children":87},{"class":34,"line":86},4,[88],{"type":15,"tag":32,"props":89,"children":90},{"style":56},[91],{"type":20,"value":74},{"type":15,"tag":93,"props":94,"children":95},"hr",{},[],{"type":15,"tag":16,"props":97,"children":98},{},[99],{"type":20,"value":100},"F-strings (formatting strings).",{"type":15,"tag":22,"props":102,"children":104},{"className":24,"code":103,"language":10,"meta":7,"style":7},"a = 10\nb = 3.141592\na_string = f\"Variable a is {a}. Pi up to 4 decimal places: {b:4f}\"\nprint(a_string)\n>>> 'Variable a is 10. Pi up to 4 decimal places: 3.1416'\n",[105],{"type":15,"tag":28,"props":106,"children":107},{"__ignoreMap":7},[108,127,144,210,224],{"type":15,"tag":32,"props":109,"children":110},{"class":34,"line":35},[111,116,121],{"type":15,"tag":32,"props":112,"children":113},{"style":62},[114],{"type":20,"value":115},"a ",{"type":15,"tag":32,"props":117,"children":118},{"style":39},[119],{"type":20,"value":120},"=",{"type":15,"tag":32,"props":122,"children":124},{"style":123},"--shiki-default:#005CC5;--shiki-dark-mode:#AE81FF;--shiki-sky-dark-mode:#AE81FF;--shiki-light-mode:#005CC5;--shiki-blue-mode:#AE81FF",[125],{"type":20,"value":126}," 10\n",{"type":15,"tag":32,"props":128,"children":129},{"class":34,"line":68},[130,135,139],{"type":15,"tag":32,"props":131,"children":132},{"style":62},[133],{"type":20,"value":134},"b ",{"type":15,"tag":32,"props":136,"children":137},{"style":39},[138],{"type":20,"value":120},{"type":15,"tag":32,"props":140,"children":141},{"style":123},[142],{"type":20,"value":143}," 3.141592\n",{"type":15,"tag":32,"props":145,"children":146},{"class":34,"line":77},[147,152,156,162,167,172,177,182,187,191,196,201,205],{"type":15,"tag":32,"props":148,"children":149},{"style":62},[150],{"type":20,"value":151},"a_string ",{"type":15,"tag":32,"props":153,"children":154},{"style":39},[155],{"type":20,"value":120},{"type":15,"tag":32,"props":157,"children":159},{"style":158},"--shiki-default:#D73A49;--shiki-dark-mode:#66D9EF;--shiki-sky-dark-mode:#66D9EF;--shiki-light-mode:#D73A49;--shiki-blue-mode:#66D9EF;--shiki-default-font-style:inherit;--shiki-dark-mode-font-style:italic;--shiki-sky-dark-mode-font-style:italic;--shiki-light-mode-font-style:inherit;--shiki-blue-mode-font-style:italic",[160],{"type":20,"value":161}," f",{"type":15,"tag":32,"props":163,"children":164},{"style":56},[165],{"type":20,"value":166},"\"Variable a is ",{"type":15,"tag":32,"props":168,"children":169},{"style":123},[170],{"type":20,"value":171},"{",{"type":15,"tag":32,"props":173,"children":174},{"style":62},[175],{"type":20,"value":176},"a",{"type":15,"tag":32,"props":178,"children":179},{"style":123},[180],{"type":20,"value":181},"}",{"type":15,"tag":32,"props":183,"children":184},{"style":56},[185],{"type":20,"value":186},". Pi up to 4 decimal places: ",{"type":15,"tag":32,"props":188,"children":189},{"style":123},[190],{"type":20,"value":171},{"type":15,"tag":32,"props":192,"children":193},{"style":62},[194],{"type":20,"value":195},"b",{"type":15,"tag":32,"props":197,"children":198},{"style":158},[199],{"type":20,"value":200},":4f",{"type":15,"tag":32,"props":202,"children":203},{"style":123},[204],{"type":20,"value":181},{"type":15,"tag":32,"props":206,"children":207},{"style":56},[208],{"type":20,"value":209},"\"\n",{"type":15,"tag":32,"props":211,"children":212},{"class":34,"line":86},[213,219],{"type":15,"tag":32,"props":214,"children":216},{"style":215},"--shiki-default:#005CC5;--shiki-dark-mode:#66D9EF;--shiki-sky-dark-mode:#66D9EF;--shiki-light-mode:#005CC5;--shiki-blue-mode:#66D9EF",[217],{"type":20,"value":218},"print",{"type":15,"tag":32,"props":220,"children":221},{"style":62},[222],{"type":20,"value":223},"(a_string)\n",{"type":15,"tag":32,"props":225,"children":227},{"class":34,"line":226},5,[228,233],{"type":15,"tag":32,"props":229,"children":230},{"style":39},[231],{"type":20,"value":232},">>>",{"type":15,"tag":32,"props":234,"children":235},{"style":56},[236],{"type":20,"value":237}," 'Variable a is 10. Pi up to 4 decimal places: 3.1416'\n",{"type":15,"tag":93,"props":239,"children":240},{},[],{"type":15,"tag":16,"props":242,"children":243},{},[244],{"type":20,"value":245},"Using docstrings to document functions.",{"type":15,"tag":22,"props":247,"children":249},{"className":24,"code":248,"language":10,"meta":7,"style":7},"def count(a: list, b: int, c: bool=True):\n    \"\"\"\n    Counts how many times `b` appears in list `a`.\n\n    Args:\n        a (list[int]) : A list of numbers.\n        b (int) : The number to look for in `a`.\n        c (bool) : If True, returns the list.\n    \"\"\"\n",[250],{"type":15,"tag":28,"props":251,"children":252},{"__ignoreMap":7},[253,338,345,353,362,370,379,388,397],{"type":15,"tag":32,"props":254,"children":255},{"class":34,"line":35},[256,261,267,272,277,282,288,293,297,301,306,310,315,319,324,328,333],{"type":15,"tag":32,"props":257,"children":258},{"style":158},[259],{"type":20,"value":260},"def",{"type":15,"tag":32,"props":262,"children":264},{"style":263},"--shiki-default:#6F42C1;--shiki-dark-mode:#A6E22E;--shiki-sky-dark-mode:#A6E22E;--shiki-light-mode:#6F42C1;--shiki-blue-mode:#A6E22E",[265],{"type":20,"value":266}," count",{"type":15,"tag":32,"props":268,"children":269},{"style":62},[270],{"type":20,"value":271},"(",{"type":15,"tag":32,"props":273,"children":275},{"style":274},"--shiki-default:#24292E;--shiki-dark-mode:#FD971F;--shiki-sky-dark-mode:#FD971F;--shiki-light-mode:#24292E;--shiki-blue-mode:#FD971F;--shiki-default-font-style:inherit;--shiki-dark-mode-font-style:italic;--shiki-sky-dark-mode-font-style:italic;--shiki-light-mode-font-style:inherit;--shiki-blue-mode-font-style:italic",[276],{"type":20,"value":176},{"type":15,"tag":32,"props":278,"children":279},{"style":62},[280],{"type":20,"value":281},": ",{"type":15,"tag":32,"props":283,"children":285},{"style":284},"--shiki-default:#005CC5;--shiki-dark-mode:#66D9EF;--shiki-sky-dark-mode:#66D9EF;--shiki-light-mode:#005CC5;--shiki-blue-mode:#66D9EF;--shiki-default-font-style:inherit;--shiki-dark-mode-font-style:italic;--shiki-sky-dark-mode-font-style:italic;--shiki-light-mode-font-style:inherit;--shiki-blue-mode-font-style:italic",[286],{"type":20,"value":287},"list",{"type":15,"tag":32,"props":289,"children":290},{"style":62},[291],{"type":20,"value":292},", ",{"type":15,"tag":32,"props":294,"children":295},{"style":274},[296],{"type":20,"value":195},{"type":15,"tag":32,"props":298,"children":299},{"style":62},[300],{"type":20,"value":281},{"type":15,"tag":32,"props":302,"children":303},{"style":284},[304],{"type":20,"value":305},"int",{"type":15,"tag":32,"props":307,"children":308},{"style":62},[309],{"type":20,"value":292},{"type":15,"tag":32,"props":311,"children":312},{"style":274},[313],{"type":20,"value":314},"c",{"type":15,"tag":32,"props":316,"children":317},{"style":62},[318],{"type":20,"value":281},{"type":15,"tag":32,"props":320,"children":321},{"style":284},[322],{"type":20,"value":323},"bool",{"type":15,"tag":32,"props":325,"children":326},{"style":39},[327],{"type":20,"value":120},{"type":15,"tag":32,"props":329,"children":330},{"style":123},[331],{"type":20,"value":332},"True",{"type":15,"tag":32,"props":334,"children":335},{"style":62},[336],{"type":20,"value":337},"):\n",{"type":15,"tag":32,"props":339,"children":340},{"class":34,"line":68},[341],{"type":15,"tag":32,"props":342,"children":343},{"style":56},[344],{"type":20,"value":74},{"type":15,"tag":32,"props":346,"children":347},{"class":34,"line":77},[348],{"type":15,"tag":32,"props":349,"children":350},{"style":56},[351],{"type":20,"value":352},"    Counts how many times `b` appears in list `a`.\n",{"type":15,"tag":32,"props":354,"children":355},{"class":34,"line":86},[356],{"type":15,"tag":32,"props":357,"children":359},{"emptyLinePlaceholder":358},true,[360],{"type":20,"value":361},"\n",{"type":15,"tag":32,"props":363,"children":364},{"class":34,"line":226},[365],{"type":15,"tag":32,"props":366,"children":367},{"style":56},[368],{"type":20,"value":369},"    Args:\n",{"type":15,"tag":32,"props":371,"children":373},{"class":34,"line":372},6,[374],{"type":15,"tag":32,"props":375,"children":376},{"style":56},[377],{"type":20,"value":378},"        a (list[int]) : A list of numbers.\n",{"type":15,"tag":32,"props":380,"children":382},{"class":34,"line":381},7,[383],{"type":15,"tag":32,"props":384,"children":385},{"style":56},[386],{"type":20,"value":387},"        b (int) : The number to look for in `a`.\n",{"type":15,"tag":32,"props":389,"children":391},{"class":34,"line":390},8,[392],{"type":15,"tag":32,"props":393,"children":394},{"style":56},[395],{"type":20,"value":396},"        c (bool) : If True, returns the list.\n",{"type":15,"tag":32,"props":398,"children":400},{"class":34,"line":399},9,[401],{"type":15,"tag":32,"props":402,"children":403},{"style":56},[404],{"type":20,"value":74},{"type":15,"tag":93,"props":406,"children":407},{},[],{"type":15,"tag":16,"props":409,"children":410},{},[411,413,419,420,426,427,433],{"type":20,"value":412},"Files and file formats: ",{"type":15,"tag":28,"props":414,"children":416},{"className":415},[],[417],{"type":20,"value":418},"JSON",{"type":20,"value":292},{"type":15,"tag":28,"props":421,"children":423},{"className":422},[],[424],{"type":20,"value":425},"JSON-lines",{"type":20,"value":292},{"type":15,"tag":28,"props":428,"children":430},{"className":429},[],[431],{"type":20,"value":432},"CSV",{"type":20,"value":434},".",{"type":15,"tag":93,"props":436,"children":437},{},[],{"type":15,"tag":439,"props":440,"children":441},"style",{},[442],{"type":20,"value":443},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark-mode .shiki span {color: var(--shiki-dark-mode);background: var(--shiki-dark-mode-bg);font-style: var(--shiki-dark-mode-font-style);font-weight: var(--shiki-dark-mode-font-weight);text-decoration: var(--shiki-dark-mode-text-decoration);}html.dark-mode .shiki span {color: var(--shiki-dark-mode);background: var(--shiki-dark-mode-bg);font-style: var(--shiki-dark-mode-font-style);font-weight: var(--shiki-dark-mode-font-weight);text-decoration: var(--shiki-dark-mode-text-decoration);}html .sky-dark-mode .shiki span {color: var(--shiki-sky-dark-mode);background: var(--shiki-sky-dark-mode-bg);font-style: var(--shiki-sky-dark-mode-font-style);font-weight: var(--shiki-sky-dark-mode-font-weight);text-decoration: var(--shiki-sky-dark-mode-text-decoration);}html.sky-dark-mode .shiki span {color: var(--shiki-sky-dark-mode);background: var(--shiki-sky-dark-mode-bg);font-style: var(--shiki-sky-dark-mode-font-style);font-weight: var(--shiki-sky-dark-mode-font-weight);text-decoration: var(--shiki-sky-dark-mode-text-decoration);}html .light-mode .shiki span {color: var(--shiki-light-mode);background: var(--shiki-light-mode-bg);font-style: var(--shiki-light-mode-font-style);font-weight: var(--shiki-light-mode-font-weight);text-decoration: var(--shiki-light-mode-text-decoration);}html.light-mode .shiki span {color: var(--shiki-light-mode);background: var(--shiki-light-mode-bg);font-style: var(--shiki-light-mode-font-style);font-weight: var(--shiki-light-mode-font-weight);text-decoration: var(--shiki-light-mode-text-decoration);}html .blue-mode .shiki span {color: var(--shiki-blue-mode);background: var(--shiki-blue-mode-bg);font-style: var(--shiki-blue-mode-font-style);font-weight: var(--shiki-blue-mode-font-weight);text-decoration: var(--shiki-blue-mode-text-decoration);}html.blue-mode .shiki span {color: var(--shiki-blue-mode);background: var(--shiki-blue-mode-bg);font-style: var(--shiki-blue-mode-font-style);font-weight: var(--shiki-blue-mode-font-weight);text-decoration: var(--shiki-blue-mode-text-decoration);}",{"title":7,"searchDepth":68,"depth":68,"links":445},[],"markdown","content:tutorials:python-conventions.md","content","tutorials/python-conventions.md","tutorials/python-conventions","md",1793934184836]