\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Cash (CashM)} \pdfinfo{ /Title (python-naming-conventions.pdf) /Creator (Cheatography) /Author (Cash (CashM)) /Subject (Python Naming Conventions Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{5141BA} \definecolor{LightBackground}{HTML}{F4F3FA} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Python Naming Conventions Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Cash (CashM)} via \textcolor{DarkBackground}{\uline{cheatography.com/123081/cs/48397/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Cash (CashM) \\ \uline{cheatography.com/cashm} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 31st August, 2026.\\ Updated 31st August, 2026.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Reference}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Python Class (10-152-117)}} \newline % Row Count 1 (+ 1) {\bf{Reference:}} {[}PEP 8 - Style Guide for Python Code{]}(https://peps.python.org/pep-0008/)% Row Count 3 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{6.5793 cm} x{4.5549 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{The Python Quick Rule}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Use in Python}} & {\bf{Preferred Convention}} & {\bf{Example}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Variables & snake\_case & \seqsplit{total\_cost} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} Functions and methods & snake\_case & \seqsplit{calculate\_total()} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Modules and packages & {\bf{short}} snake\_case & \seqsplit{grade\_tools}.py \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} Classes & PascalCase & \seqsplit{GradeCalculator} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} Exceptions & PascalCase & \seqsplit{InvalidGradeError} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} Constants & \seqsplit{UPPER\_SNAKE\_CASE} & \seqsplit{MAX\_ATTEMPTS} = 3 \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{Use snake\_case for most names, PascalCase for classes, and UPPER\_SNAKE\_CASE for \newline constants. Names should describe the value, behavior, or responsibility they represent.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.1057 cm} x{1.647 cm} x{5.4351 cm} x{4.2822 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{17.67cm}}{\bf\textcolor{white}{Common naming conventions}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Convention}} & {\bf{Example}} & {\bf{Where you may see it}} & {\bf{Python status}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} lowercase & score & Simple names & Common \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} snake\_case & \seqsplit{student\_score} & Python variables, functions, methods, modules & {\emph{PEP 8 preferred}} \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} PascalCase \seqsplit{(CapitalCase)} & \seqsplit{StudentScore} & Classes and exceptions & {\emph{PEP 8 preferred}} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} camelCase & \seqsplit{studentScore} & JavaScript, Java, C\# & Avoid for Python names \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{UPPER\_SNAKE\_CASE} \seqsplit{(SCREAMING\_SNAKE\_CASE)} & \seqsplit{MAX\_SCORE} & Constants and \seqsplit{configuration} & {\emph{PEP 8 preferred}} \tn % Row Count 19 (+ 4) % Row 6 \SetRowColor{LightBackground} kebab-case \seqsplit{(train-case)} & \seqsplit{student-score} & URLs, CSS classes, command-line options & Not valid for Python \seqsplit{identifiers} \tn % Row Count 23 (+ 4) % Row 7 \SetRowColor{white} dot.case & \seqsplit{student}.score & Module paths and attribute access & Not a single \seqsplit{identifier} \tn % Row Count 27 (+ 4) % Row 8 \SetRowColor{LightBackground} Title Case & \seqsplit{Student} Score & Headings and human-facing labels & Not a Python \seqsplit{identifier} \tn % Row Count 31 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.1057 cm} x{1.647 cm} x{5.4351 cm} x{4.2822 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{17.67cm}}{\bf\textcolor{white}{Common naming conventions (cont)}} \tn % Row 9 \SetRowColor{LightBackground} flatcase & \seqsplit{studentscore} & Occasional file names or labels & Rare; less readable \tn % Row Count 3 (+ 3) % Row 10 \SetRowColor{white} UPPERCASE & \seqsplit{MAXSCORE} & Acronyms or legacy systems & Rare; avoid for new Python names \tn % Row Count 7 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.9167 cm} x{3.0366 cm} x{6.9167 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Python-specific underscore conventions}} \tn % Row 0 \SetRowColor{LightBackground} Pattern & \seqsplit{Example} & Meaning \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Leading underscore & \seqsplit{\_cached\_result} & Conventionally internal or non-public. from module import * does not import it. \tn % Row Count 6 (+ 5) % Row 2 \SetRowColor{LightBackground} Trailing underscore & class\_ & Avoids a conflict with a Python keyword or built-in name. \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} Double leading underscore & \seqsplit{\_\_balance} & Python applies name mangling inside a class to help avoid accidental subclass conflicts. \tn % Row Count 16 (+ 6) % Row 4 \SetRowColor{LightBackground} Double leading and trailing underscores (dunder) & \seqsplit{\_\_init\_\_}, \seqsplit{\_\_len\_\_} & Special names defined by Python. Do not invent new dunder names. \tn % Row Count 20 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Identifier rules}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{• Start with a letter or underscore, followed by letters, digits, or underscores. \newline % Row Count 2 (+ 2) • Do not start with a digit: 2nd\_attempt is invalid. \newline % Row Count 4 (+ 2) • Do not use spaces or hyphens: student score and student-score are invalid. \newline % Row Count 6 (+ 2) • Python is case-sensitive: score, Score, and SCORE are different names. \newline % Row Count 8 (+ 2) • Do not reuse Python keywords such as class, for, if, or return. \newline % Row Count 10 (+ 2) • Prefer descriptive names: average\_score is clearer than avg when space allows.% Row Count 12 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{PEP 8 reminders}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{• Choose names that reveal intent: is\_complete is clearer than flag. \newline % Row Count 2 (+ 2) • Use verbs for actions: save\_file(), calculate\_total(), and display\_menu(). \newline % Row Count 4 (+ 2) • Use nouns for values and objects: student\_name, shopping\_cart, and report. \newline % Row Count 6 (+ 2) • Use boolean names that read like questions: is\_valid, has\_access, and can\_submit. \newline % Row Count 8 (+ 2) • Be consistent. A project using student\_name should not also use studentName.% Row Count 10 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}