\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{Arshdeep} \pdfinfo{ /Title (introduction-to-python.pdf) /Creator (Cheatography) /Author (Arshdeep) /Subject (Introduction to Python 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}{154EA3} \definecolor{LightBackground}{HTML}{F0F3F9} \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{Introduction to Python Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Arshdeep} via \textcolor{DarkBackground}{\uline{cheatography.com/201979/cs/42848/}}} \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}Arshdeep \\ \uline{cheatography.com/arshdeep} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 3rd April, 2024.\\ 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{multicols*}{2} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Looping Statements}} \tn % Row 0 \SetRowColor{LightBackground} For Loop & `for item in iterable:\{\{nl\}\} \# Code block to be executed for each item` \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Example & `for i in range(5):\{\{nl\}\} print(i)` \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} Output & 0\{\{nl\}\}1\{\{nl\}\}2\{\{nl\}\}3\{\{nl\}\}4 \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} While Loop & `while condition:\{\{nl\}\} \# Code block to be executed as long as condition is True` \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} Example & `count = 0\{\{nl\}\} while count \textless{} 5:\{\{nl\}\} print(count)\{\{nl\}\} count += 1` \tn % Row Count 16 (+ 4) % Row 5 \SetRowColor{white} Output & 0\{\{nl\}\}1\{\{nl\}\}2\{\{nl\}\}3\{\{nl\}\}4 \tn % Row Count 18 (+ 2) % Row 6 \SetRowColor{LightBackground} break & Terminates the loop immediately \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} continue & Skips the rest of the code inside the loop for the current iteration and proceeds to the next iteration \tn % Row Count 25 (+ 5) % Row 8 \SetRowColor{LightBackground} pass & Acts as a placeholder, does nothing \tn % Row Count 27 (+ 2) % Row 9 \SetRowColor{white} Nested Loops & `for i in range(3):\{\{nl\}\} for j in range(2):\{\{nl\}\} print(i, j)` \tn % Row Count 31 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Looping Statements (cont)}} \tn % Row 10 \SetRowColor{LightBackground} List Comprehension & `{[}expression for item in iterable{]}` \tn % Row Count 2 (+ 2) % Row 11 \SetRowColor{white} Dictionary Comprehension & `\{key\_expression: value\_expression for item in iterable\}` \tn % Row Count 5 (+ 3) % Row 12 \SetRowColor{LightBackground} Generator Expression & `(expression for item in iterable)` \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Evolution of Python}} \tn % Row 0 \SetRowColor{LightBackground} Birth of Python (1989-1991) & Created by Guido van Rossum, Python emerged in the late 1980s as a successor to the ABC language. Its name was inspired by Monty Python's Flying Circus, a British sketch comedy series. \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} Python 1.0 (1994) & Python 1.0 was released with features like lambda, map, filter, and reduce. Its simplicity and readability gained attention in the programming community. \tn % Row Count 17 (+ 8) % Row 2 \SetRowColor{LightBackground} Python 2.x Series (2000-2008) & Python 2 introduced significant improvements and became widely adopted. However, this series faced challenges with compatibility issues when Python 3 was released. \tn % Row Count 25 (+ 8) % Row 3 \SetRowColor{white} Python 3.x Series (2008-present) & Python 3 marked a major overhaul of the language, aiming to fix inconsistencies and introduce new features while maintaining backward compatibility. Despite initial resistance, it eventually gained widespread acceptance. \tn % Row Count 36 (+ 11) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Evolution of Python (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Python Enhancement Proposals (PEPs) & PEPs serve as the formal mechanisms for proposing major changes to Python. They facilitate community discussion and decision-making processes, ensuring Python's evolution reflects the needs of its users. \tn % Row Count 10 (+ 10) % Row 5 \SetRowColor{white} Community and Ecosystem Growth & Python's open-source nature has fostered a vibrant community, contributing to a vast ecosystem of libraries, frameworks, and tools. This growth has propelled Python to become one of the most popular and versatile programming languages worldwide. \tn % Row Count 22 (+ 12) % Row 6 \SetRowColor{LightBackground} Recent Developments & Continual updates and enhancements keep Python relevant and competitive in the ever-changing landscape of programming languages. Recent developments include optimizations for performance, improvements in concurrency, and enhancements in data science and machine learning capabilities. \tn % Row Count 36 (+ 14) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Evolution of Python (cont)}} \tn % Row 7 \SetRowColor{LightBackground} Future Directions & Python continues to evolve, with ongoing efforts to enhance performance, maintainability, and ease of use. The community-driven development model ensures that Python remains adaptable to emerging technologies and evolving programming paradigms. \tn % Row Count 12 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Rules for Identifiers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Must start with a letter (a-z, A-Z) or underscore (\_).} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Can be followed by letters, digits (0-9), or underscores.} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Python identifiers are case-sensitive.} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Cannot be a reserved word or keyword.} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Identity Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Is: is} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Is not: is not} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Membership Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{In: in} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Not in: not in} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} Integer (int) & Represents whole numbers. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Float (float) & Represents floating-point numbers (decimal numbers). \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} String (str) & Represents sequences of characters enclosed in quotes (' or "). \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} Boolean (bool) & Represents truth values True or False. \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} List & Ordered collection of items, mutable. \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} Tuple & Ordered collection of items, immutable. \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} Dictionary (dict) & Collection of key-value pairs, unordered. \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} Set & Collection of unique items, unordered. \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} Integer (int) & Represents whole numbers. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Float (float) & Represents floating-point numbers (decimal numbers). \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} String (str) & Represents sequences of characters enclosed in quotes (' or "). \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} Boolean (bool) & Represents truth values True or False. \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} List & Ordered collection of items, mutable. \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} Tuple & Ordered collection of items, immutable. \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} Dictionary (dict) & Collection of key-value pairs, unordered. \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} Set & Collection of unique items, unordered. \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Features of Python}} \tn % Row 0 \SetRowColor{LightBackground} Simple and Readable Syntax & Python's syntax is designed to be simple and readable, making it easy for beginners to learn and understand. Its clean and concise syntax reduces the cost of program maintenance. \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} Interpreted Language & Python is an interpreted language, meaning that it does not need to be compiled before execution. This allows for rapid development and testing of code. \tn % Row Count 16 (+ 7) % Row 2 \SetRowColor{LightBackground} High-Level Language & Python abstracts low-level details like memory management and provides constructs like objects, functions, and modules, allowing developers to focus on solving problems rather than dealing with system-level concerns. \tn % Row Count 26 (+ 10) % Row 3 \SetRowColor{white} Dynamic Typing & Python is dynamically typed, meaning you don't need to declare the data type of variables explicitly. This makes Python code shorter and more flexible. \tn % Row Count 33 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Features of Python (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Object-Oriented & Python supports object-oriented programming (OOP) paradigms, allowing developers to create reusable and modular code by defining classes and objects. \tn % Row Count 7 (+ 7) % Row 5 \SetRowColor{white} Extensive Standard Library & Python comes with a vast standard library that provides modules and functions for a wide range of tasks, from file I/O to networking to web development. This reduces the need for third-party libraries for many common tasks. \tn % Row Count 18 (+ 11) % Row 6 \SetRowColor{LightBackground} Cross-Platform Compatibility & Python code can run on various platforms such as Windows, macOS, and Linux without modification, making it highly portable. \tn % Row Count 24 (+ 6) % Row 7 \SetRowColor{white} Dynamic Memory Allocation & Python uses dynamic memory allocation and garbage collection, automatically managing memory usage and freeing up memory when objects are no longer needed. \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Features of Python (cont)}} \tn % Row 8 \SetRowColor{LightBackground} Strong Community Support & Python has a large and active community of developers who contribute to its growth by creating libraries, frameworks, and tools. This vibrant community ensures that there are resources and support available for developers at all levels. \tn % Row Count 11 (+ 11) % Row 9 \SetRowColor{white} Integration Capabilities & Python can easily integrate with other languages like C/C++, allowing developers to leverage existing code and libraries written in other languages. \tn % Row Count 18 (+ 7) % Row 10 \SetRowColor{LightBackground} Ease of Learning and Deployment & Python's simplicity and readability make it an excellent choice for beginners, and its extensive documentation and community support make it easy to learn and deploy for both small-scale and large-scale projects. \tn % Row Count 28 (+ 10) % Row 11 \SetRowColor{white} Scalability & While initially known for its simplicity and ease of use, Python is also scalable and can handle large-scale projects effectively. With frameworks like Django and Flask for web development, and libraries like NumPy and Pandas for data science, Python is suitable for a wide range of applications, from small scripts to enterprise-level systems. \tn % Row Count 44 (+ 16) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Comparison Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Equal to: ==} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Not equal to: !=} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Greater than: \textgreater{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Less than: \textless{}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Greater than or equal to: \textgreater{}=} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Less than or equal to: \textless{}=} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Logical Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Logical AND: and} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Logical OR: or} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Logical NOT: not} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} Defining a Function & `def function\_name(parameters):\{\{nl\}\} """docstring"""\{\{nl\}\} \# code block\{\{nl\}\} return value` \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} Calling a Function & `result = \seqsplit{function\_name(arguments)`} \tn % Row Count 7 (+ 2) % Row 2 \SetRowColor{LightBackground} Positional Parameters & `def greet(name):\{\{nl\}\} print("Hello,", name)\{\{nl\}\} greet("Alice") \# Output: Hello, Alice` \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} Keyword Parameters & `def greet(name, greeting):\{\{nl\}\} print(greeting, name)\{\{nl\}\} greet(name="Bob", greeting="Hi")\{\{nl\}\} \# Output: Hi Bob` \tn % Row Count 18 (+ 6) % Row 4 \SetRowColor{LightBackground} Default Parameters & `def greet(name, greeting="Hello"):\{\{nl\}\} print(greeting, name)\{\{nl\}\} greet("Alice")\{\{nl\}\} \# Output: Hello Alice` \tn % Row Count 24 (+ 6) % Row 5 \SetRowColor{white} *args (Non-keyword Arguments) & `def add(*args):\{\{nl\}\} return sum(args)\{\{nl\}\} add(1, 2, 3) \# Output: 6` \tn % Row Count 28 (+ 4) % Row 6 \SetRowColor{LightBackground} **kwargs (Keyword Arguments) & `def details(**kwargs):\{\{nl\}\} print(kwargs)\{\{nl\}\} details(name="Alice", age=30) \{\{nl\}\}\# Output: \{'name': 'Alice', 'age': 30\}` \tn % Row Count 34 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Functions (cont)}} \tn % Row 7 \SetRowColor{LightBackground} Docstrings & `def function\_name(parameters):\{\{nl\}\} """Description of the function"""\{\{nl\}\} \# code block\{\{nl\}\} return value\{\{nl\}\} \seqsplit{print(function\_name.\_\_doc\_\_)`} \tn % Row Count 7 (+ 7) % Row 8 \SetRowColor{white} Return Statement & def add(a, b):\{\{nl\}\} return a + b\{\{nl\}\} result = add(3, 5) \# Output: 8 \tn % Row Count 11 (+ 4) % Row 9 \SetRowColor{LightBackground} Local Scope & Variables defined inside a function have local scope. \tn % Row Count 14 (+ 3) % Row 10 \SetRowColor{white} Global Scope & Variables defined outside functions have global scope. \tn % Row Count 17 (+ 3) % Row 11 \SetRowColor{LightBackground} Lambda Functions & `double = lambda x: x * 2\{\{nl\}\} print(double(5)) \# Output: 10` \tn % Row Count 20 (+ 3) % Row 12 \SetRowColor{white} Recursive Functions & `def factorial(n):\{\{nl\}\} if n == 0:\{\{nl\}\} return 1\{\{nl\}\} else:\{\{nl\}\} return n * factorial(n-1)\{\{nl\}\} print(factorial(5)) \# Output: 120` \tn % Row Count 27 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Exception Handling}} \tn % Row 0 \SetRowColor{LightBackground} What is an Exception? & An exception is an error that occurs during the execution of a program. It disrupts the normal flow of the program's instructions. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} try-except block & `try:\{\{nl\}\} \# Code that may raise an exception \{\{nl\}\}except ExceptionType:\{\{nl\}\} \# Code to handle the exception` \tn % Row Count 12 (+ 6) % Row 2 \SetRowColor{LightBackground} try-except-else block & `try:\{\{nl\}\} \# Code that may raise an exception \{\{nl\}\}except ExceptionType:\{\{nl\}\} \# Code to handle the exception \{\{nl\}\}else:\{\{nl\}\} \# Code to execute if no exception occurs` \tn % Row Count 20 (+ 8) % Row 3 \SetRowColor{white} \seqsplit{try-except-finally} block & `try:\{\{nl\}\} \# Code that may raise an exception \{\{nl\}\}except ExceptionType:\{\{nl\}\} \# Code to handle the exception \{\{nl\}\}finally:\{\{nl\}\} \# Code that will execute no matter what` \tn % Row Count 29 (+ 9) % Row 4 \SetRowColor{LightBackground} Built-in Exceptions & Examples include TypeError, ValueError, ZeroDivisionError, etc. \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Exception Handling (cont)}} \tn % Row 5 \SetRowColor{LightBackground} Raising Exceptions & `raise ExceptionType("Error message")` \tn % Row Count 2 (+ 2) % Row 6 \SetRowColor{white} Custom Exceptions & `class CustomError(Exception):\{\{nl\}\} def \_\_init\_\_(self, message):\{\{nl\}\} self.message = message` \tn % Row Count 7 (+ 5) % Row 7 \SetRowColor{LightBackground} Handling Multiple Exceptions & `try:\{\{nl\}\} \# Code \{\{nl\}\}except (ExceptionType1, ExceptionType2) as e:\{\{nl\}\} \# Handle both exceptions` \tn % Row Count 12 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File Handling}} \tn % Row 0 \SetRowColor{LightBackground} Opening a File & `file = open("filename.txt", "r")` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Closing a File & `file.close()` \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} Reading from a File & `content = file.read()` \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Writing to a File & `file.write("Hello, world!")` \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} Appending to a File & `file = open("filename.txt", "a") \{\{nl\}\}file.write("New content")` \tn % Row Count 11 (+ 4) % Row 5 \SetRowColor{white} Iterating Over Lines & for line in file:\{\{nl\}\} print(line) \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} Checking File Existence & import os.path \{\{nl\}\}if \seqsplit{os.path.exists("filename}.txt"):\{\{nl\}\} print("File exists") \tn % Row Count 18 (+ 5) % Row 7 \SetRowColor{white} File Handling with Context Managers & `with open("filename.txt", "r") as file:\{\{nl\}\} content = file.read()\{\{nl\}\} \# file automatically closed after exiting the 'with' block` \tn % Row Count 25 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Arithmetic Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Addition: +} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Subtraction: -} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Multiplication: *} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Division: /} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Modulus: \%} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Exponentiation: **} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.76 cm} x{6.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Common Functions}} \tn % Row 0 \SetRowColor{LightBackground} print() & Output text or variables to the console. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} input() & Receive user input from the console. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} len() & Calculate the length of a sequence (e.g., string, list, tuple). \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} range() & Generate a sequence of numbers within a specified range. \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} type() & Determine the type of a variable or value. \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} int() & Convert a value to an integer. \tn % Row Count 12 (+ 1) % Row 6 \SetRowColor{LightBackground} float() & Convert a value to a floating-point number. \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} str() & Convert a value to a string. \tn % Row Count 15 (+ 1) % Row 8 \SetRowColor{LightBackground} list() & Convert a sequence (e.g., string, tuple) to a list. \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} tuple() & Convert a sequence (e.g., string, list) to a tuple. \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} dict() & Create a dictionary or convert a sequence of key-value pairs into a dictionary. \tn % Row Count 22 (+ 3) % Row 11 \SetRowColor{white} \seqsplit{sorted()} & Return a new sorted list from the elements of an iterable. \tn % Row Count 24 (+ 2) % Row 12 \SetRowColor{LightBackground} max() & Return the largest item in an iterable or the largest of two or more arguments. \tn % Row Count 27 (+ 3) % Row 13 \SetRowColor{white} min() & Return the smallest item in an iterable or the smallest of two or more arguments. \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{1.76 cm} x{6.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Common Functions (cont)}} \tn % Row 14 \SetRowColor{LightBackground} sum() & Return the sum of all elements in an iterable. \tn % Row Count 2 (+ 2) % Row 15 \SetRowColor{white} abs() & Return the absolute value of a number. \tn % Row Count 4 (+ 2) % Row 16 \SetRowColor{LightBackground} round() & Round a floating-point number to a specified precision. \tn % Row Count 6 (+ 2) % Row 17 \SetRowColor{white} zip() & Combine multiple iterables into tuples. \tn % Row Count 8 (+ 2) % Row 18 \SetRowColor{LightBackground} \seqsplit{enumerate()} & Return an enumerate object, which yields pairs of index and value. \tn % Row Count 11 (+ 3) % Row 19 \SetRowColor{white} map() & Apply a function to every item in an iterable. \tn % Row Count 13 (+ 2) % Row 20 \SetRowColor{LightBackground} \seqsplit{filter()} & Construct an iterator from those elements of an iterable for which a function returns true. \tn % Row Count 16 (+ 3) % Row 21 \SetRowColor{white} \seqsplit{reduce()} & Apply a rolling computation to sequential pairs of values in an iterable. \tn % Row Count 19 (+ 3) % Row 22 \SetRowColor{LightBackground} any() & Return True if any element of the iterable is true. \tn % Row Count 21 (+ 2) % Row 23 \SetRowColor{white} all() & Return True if all elements of the iterable are true. \tn % Row Count 23 (+ 2) % Row 24 \SetRowColor{LightBackground} dir() & Return a list of valid attributes for the specified object. \tn % Row Count 25 (+ 2) % Row 25 \SetRowColor{white} help() & Access Python's built-in help system. \tn % Row Count 27 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Conditional Statements}} \tn % Row 0 \SetRowColor{LightBackground} If Statement & `if condition:\{\{nl\}\} \# Code to execute if condition is True` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} If-else Statement & `if condition:\{\{nl\}\} \# Code to execute if condition is True\{\{nl\}\} else:\{\{nl\}\} \# Code to execute if condition is False` \tn % Row Count 9 (+ 6) % Row 2 \SetRowColor{LightBackground} If-elif-else Statement & `if condition1:\{\{nl\}\} \# Code to execute if condition1 is True\{\{nl\}\} elif condition2:\{\{nl\}\} \# Code to execute if condition2 is True\{\{nl\}\} else:\{\{nl\}\} \# Code to execute if all conditions are False` \tn % Row Count 18 (+ 9) % Row 3 \SetRowColor{white} Nested If Statements & `if condition1:\{\{nl\}\} if condition2:\{\{nl\}\} \# Code to execute if both condition1 and condition2 are True` \tn % Row Count 24 (+ 6) % Row 4 \SetRowColor{LightBackground} Ternary Conditional Operator & `result = true\_value if condition else false\_value` \tn % Row Count 27 (+ 3) % Row 5 \SetRowColor{white} Short Circuit Evaluation & `\# Example using 'and'\{\{nl\}\} if x \textgreater{} 0 and y \textless{} 10:\{\{nl\}\} \# Code here\{\{nl\}\}\{\{nl\}\} \# Example using 'or'\{\{nl\}\} if a == 0 or b == 0:\{\{nl\}\} \# Code here` \tn % Row Count 34 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Conditional Statements (cont)}} \tn % Row 6 \SetRowColor{LightBackground} Membership Test & `if item in list:\{\{nl\}\} \# Code to execute if item is present in list` \tn % Row Count 4 (+ 4) % Row 7 \SetRowColor{white} Identity Test & `if x is y:\{\{nl\}\} \# Code to execute if x and y refer to the same object` \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Bitwise Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Bitwise AND: \&} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Bitwise OR: |} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Bitwise XOR: \textasciicircum{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Bitwise NOT: \textasciitilde{}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Left shift: \textless{}\textless{}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Right shift: \textgreater{}\textgreater{}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Assignment Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Assign value: =} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Add and assign: +=} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Subtract and assign: -=} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Multiply and assign: *=} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Divide and assign: /=} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Modulus and assign: \%=} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Exponentiation and assign: **=} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.8 cm} x{5.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} Variable & Variables are used to store data values. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Variable Declaration & No explicit declaration needed. Just assign a value to a name. \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Variable Naming & Follow naming conventions. Use descriptive names, avoid reserved words, and start with a letter or underscore. \tn % Row Count 10 (+ 5) % Row 3 \SetRowColor{white} Data Types & Variables can hold various data types such as integers, floats, strings, lists, tuples, dictionaries, etc. \tn % Row Count 15 (+ 5) % Row 4 \SetRowColor{LightBackground} Dynamic Typing & Python is dynamically typed, meaning you can reassign variables to different data types. \tn % Row Count 19 (+ 4) % Row 5 \SetRowColor{white} Example & `\# Variable assignment \{\{nl\}\}x = 10 \{\{nl\}\}name = "Alice" \{\{nl\}\}is\_student = True` \tn % Row Count 23 (+ 4) % Row 6 \SetRowColor{LightBackground} Variable Reassignment: & `x = 10 print(x) \# Output: 10 \{\{nl\}\}x = "Hello" \{\{nl\}\}print(x) \# Output: Hello` \tn % Row Count 27 (+ 4) % Row 7 \SetRowColor{white} Multiple Assignment & `a, b, c = 1, 2, 3` \tn % Row Count 29 (+ 2) % Row 8 \SetRowColor{LightBackground} Constants & `PI = 3.14159` \tn % Row Count 30 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Best Practices for Identifiers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Use descriptive names for better code readability.} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Avoid using single letters or abbreviations that may be ambiguous.} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Follow naming conventions (e.g., snake\_case for variables and functions, PascalCase for class names).} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.76 cm} x{6.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Tokens}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Identifiers} & These are names given to entities like variables, functions, classes, etc. They must start with a letter or underscore and can be followed by letters, digits, or underscores. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \seqsplit{Keywords} & Python has reserved words that have special meanings and cannot be used as identifiers. Examples include if, else, for, while, def, class, etc. \tn % Row Count 11 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{Literals} & These are the raw data values used in a program. Common types of literals in Python include integers, floating-point numbers, strings, and boolean values. \tn % Row Count 16 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{Operators} & Operators are symbols used to perform operations on operands. Python supports various types of operators such as arithmetic operators (+, -, *, /), assignment operators (=, +=, -=), comparison operators (==, !=, \textless{}, \textgreater{}), logical operators (and, or, not), etc. \tn % Row Count 25 (+ 9) % Row 4 \SetRowColor{LightBackground} \seqsplit{Delimiters} & Delimiters are characters used to define the structure of a program. Examples include parentheses (), braces \{\}, square brackets {[}{]}, commas ,, colons :, etc. \tn % Row Count 31 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{1.76 cm} x{6.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Tokens (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \seqsplit{Comments} & Comments are used to annotate code and are ignored by the Python interpreter. They start with the \# symbol for single-line comments or are enclosed within triple quotes """ for multi-line comments. \tn % Row Count 7 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Applications of Python}} \tn % Row 0 \SetRowColor{LightBackground} Web Development & Python's frameworks like Django and Flask are widely used for building web applications due to their simplicity and scalability. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Data Science & Python's libraries like NumPy, Pandas, and Matplotlib make it a preferred choice for data analysis, visualization, and machine learning tasks. \tn % Row Count 15 (+ 8) % Row 2 \SetRowColor{LightBackground} Artificial Intelligence and Machine Learning & Python provides extensive libraries such as TensorFlow, Keras, and PyTorch, making it popular for AI and ML projects. \tn % Row Count 21 (+ 6) % Row 3 \SetRowColor{white} Automation and Scripting & Python's ease of use and readability make it ideal for automating repetitive tasks and scripting. \tn % Row Count 26 (+ 5) % Row 4 \SetRowColor{LightBackground} Game Development & Python's simplicity and versatility are leveraged in game development frameworks like Pygame. \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Applications of Python (cont)}} \tn % Row 5 \SetRowColor{LightBackground} Desktop GUI Applications & Libraries such as Tkinter and PyQt allow developers to create cross-platform desktop GUI applications easily. \tn % Row Count 6 (+ 6) % Row 6 \SetRowColor{white} Scientific Computing & Python is widely used in scientific computing for simulations, mathematical modeling, and data analysis in fields such as physics, engineering, and biology. \tn % Row Count 14 (+ 8) % Row 7 \SetRowColor{LightBackground} Finance and Trading & Python is extensively used in finance for tasks like algorithmic trading, risk management, and quantitative analysis due to its robust libraries and ease of integration. \tn % Row Count 23 (+ 9) % Row 8 \SetRowColor{white} Education & Python's readability and simplicity make it an excellent choice for teaching programming to beginners, as well as for educational software development. \tn % Row Count 31 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Applications of Python (cont)}} \tn % Row 9 \SetRowColor{LightBackground} Networking & Python's libraries like socket and Twisted are used for network programming, making it a popular choice for developing network-related applications. \tn % Row Count 8 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Paradigms of Python}} \tn % Row 0 \SetRowColor{LightBackground} Imperative Programming & Focuses on describing how a program operates through a sequence of statements. Python's imperative style involves defining functions, loops, and conditional statements to control program flow. \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} Object-Oriented Programming (OOP) & Emphasizes the creation of objects which encapsulate data and behavior. Python supports classes, inheritance, polymorphism, and encapsulation, enabling developers to structure their code in a modular and reusable manner. \tn % Row Count 19 (+ 10) % Row 2 \SetRowColor{LightBackground} Functional Programming & Treats computation as the evaluation of mathematical functions. Python supports functional programming concepts such as higher-order functions, lambda expressions, and immutable data structures. Functional programming encourages writing pure functions without side effects, enhancing code readability and testability. \tn % Row Count 34 (+ 15) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Paradigms of Python (cont)}} \tn % Row 3 \SetRowColor{LightBackground} Procedural Programming & Involves organizing code into procedures or functions to perform tasks. Python supports procedural programming by allowing the creation of functions and modules to break down tasks into smaller, manageable units. \tn % Row Count 10 (+ 10) % Row 4 \SetRowColor{white} Aspect-Oriented Programming (AOP) & Focuses on separating cross-cutting concerns such as logging, authentication, and error handling from the main program logic. While Python doesn't provide built-in AOP support, libraries like AspectLib and Pythoscope offer AOP capabilities through decorators and metaprogramming. \tn % Row Count 23 (+ 13) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Modules}} \tn % Row 0 \SetRowColor{LightBackground} What are Modules? & Modules in Python are files containing Python code. \{\{nl\}\}They can define functions, classes, and variables. \{\{nl\}\}Python code in one module can be reused in another module. \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} Why Use Modules? & Encapsulation: Keep related code together for better organization. \{\{nl\}\}Reusability: Write code once and reuse it in multiple places. \{\{nl\}\}Namespacing: Avoid naming conflicts by using module namespaces. \tn % Row Count 20 (+ 11) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Importing Modules} \tn % Row Count 21 (+ 1) % Row 3 \SetRowColor{white} Use the import keyword to import a module. & `import module\_name` \tn % Row Count 24 (+ 3) % Row 4 \SetRowColor{LightBackground} Use from keyword to import specific items from a module. & `from module\_name import item1, item2` \tn % Row Count 27 (+ 3) % Row 5 \SetRowColor{white} Standard Library Modules & Python comes with a rich standard library of modules for various tasks. \{\{nl\}\}Examples: math, os, datetime, random, json, csv, etc. \tn % Row Count 34 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Modules (cont)}} \tn % Row 6 \SetRowColor{LightBackground} Third-Party Modules & Extensive collection of third-party modules available via the Python Package Index (PyPI). \tn % Row Count 5 (+ 5) % Row 7 \SetRowColor{white} Install third-party modules using pip, the Python package manager. & `pip install module\_name` \tn % Row Count 9 (+ 4) % Row 8 \SetRowColor{LightBackground} Creating Modules & To create your own module, simply save Python code in a .py file.\{\{nl\}\}Functions, classes, and variables defined in the file become accessible when the module is imported. \tn % Row Count 18 (+ 9) % Row 9 \SetRowColor{white} Special Attributes & \_\_name\_\_: Name of the module. When a module is run as a script, its \_\_name\_\_ is set to "\_\_main\_\_".\{\{nl\}\}\_\_file\_\_: Path to the module's source file. \tn % Row Count 26 (+ 8) % Row 10 \SetRowColor{LightBackground} Best Practices & Use meaningful names for modules.\{\{nl\}\}Document your modules using docstrings.\{\{nl\}\}Avoid polluting the global namespace by importing only what you need.\{\{nl\}\}Follow PEP 8 guidelines for code style. \tn % Row Count 36 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Modules (cont)}} \tn % Row 11 \SetRowColor{LightBackground} Importing standard library module: & `import math\{\{nl\}\}print(math.pi)` \tn % Row Count 2 (+ 2) % Row 12 \SetRowColor{white} Importing specific items & `from math import pi, sqrt \{\{nl\}\}print(pi)` \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Object Oriented Programming}} \tn % Row 0 \SetRowColor{LightBackground} Object-Oriented Programming (OOP) in Python & Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of objects, which can contain data (attributes) and code (methods). Python supports OOP principles, making it versatile and powerful for building complex systems. \tn % Row Count 13 (+ 13) % Row 1 \SetRowColor{white} Class & A class is a blueprint for creating objects. \tn % Row Count 16 (+ 3) % Row 2 \SetRowColor{LightBackground} Object & An object is an instance of a class, representing a specific entity in your program. \tn % Row Count 21 (+ 5) % Row 3 \SetRowColor{white} Encapsulation & Encapsulation refers to bundling data (attributes) and methods that operate on the data within a single unit, i.e., a class. \{\{nl\}\}It helps in data hiding and abstraction, enabling better control over data access and modification. \tn % Row Count 33 (+ 12) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Object Oriented Programming (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Inheritance & Inheritance allows a class (subclass/child class) to inherit attributes and methods from another class (superclass/parent class). \{\{nl\}\}It promotes code reuse and facilitates building hierarchical relationships between classes. \tn % Row Count 12 (+ 12) % Row 5 \SetRowColor{white} Polymorphism & Polymorphism enables a single interface to be used for different data types or objects. \{\{nl\}\}It allows methods to behave differently based on the object they are called on, promoting flexibility and extensibility. \tn % Row Count 23 (+ 11) % Row 6 \SetRowColor{LightBackground} Modularity & OOP promotes modular design, making code more organized and easier to maintain. \tn % Row Count 27 (+ 4) % Row 7 \SetRowColor{white} Reusability & Through inheritance and polymorphism, code reuse is facilitated, reducing redundancy. \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Object Oriented Programming (cont)}} \tn % Row 8 \SetRowColor{LightBackground} Scalability & OOP supports building large-scale applications by structuring code into manageable units. \tn % Row Count 5 (+ 5) % Row 9 \SetRowColor{white} Abstraction & OOP allows developers to focus on high-level functionality without worrying about implementation details. \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}