{"@attributes":{"version":"2.0"},"channel":{"title":"Python on Linode Guides & Tutorials","link":"https:\/\/www.linode.com\/docs\/guides\/development\/python\/","description":"Recent content in Python on Linode Guides & Tutorials","generator":"Hugo","language":"en-us","lastBuildDate":"Tue, 28 May 2024 00:00:00 +0000","item":[{"title":"Getting Started with Black and isort","link":"https:\/\/www.linode.com\/docs\/guides\/getting-started-with-black-and-isort\/","pubDate":"Thu, 15 Jun 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/getting-started-with-black-and-isort\/","description":"<p><a\n href=\"https:\/\/www.linode.com\/docs\/guides\/development\/python\/\"\n \n >Python<\/a\n > is one of the world&rsquo;s most widely used programming languages, widely adopted in web development, data science, and embedded systems. Python&rsquo;s formal syntax is somewhat open, as it permits a considerable range of styles. This allows programmers to indent, punctuate, and name according to their personal preferences.<\/p>"},{"title":"How to Get the Current Directory in Python","link":"https:\/\/www.linode.com\/docs\/guides\/python-get-current-directory\/","pubDate":"Mon, 12 Jun 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-get-current-directory\/","description":"<p>Programs often need to look for, read, and write specific files in a special location. By convention, and with support from the operating system, programs maintain a current working directory used as the context for many of their files. There may also be fixed directories and files that are special to the program, such as the configuration files for editors and IDEs.<\/p>"},{"title":"Modules in Python: Remove Files & Directories","link":"https:\/\/www.linode.com\/docs\/guides\/python-delete-file\/","pubDate":"Mon, 12 Jun 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-delete-file\/","description":"<p>Many applications use temporary files to hold intermediate results in their execution. A program, for example, may process several gigabytes of data in multiple passes because trying to hold it all in memory can exceed the ability of the system, even with a large swap store. This is true when multiple copies of an application are running. Holding all the data in memory can slow down the application because the virtual memory system has to keep paging data in and out of working memory. When the application is finished with the temporary files, it\u2019s a good idea to delete that working file, to free up the disk space.<\/p>"},{"title":"Getting Started with Python Sets and Python Set Operations","link":"https:\/\/www.linode.com\/docs\/guides\/python-sets\/","pubDate":"Sun, 23 Apr 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-sets\/","description":"<p>Pythons sets are unordered collections modeled on mathematical sets, in which elements are unique. Python sets support the logical operations of mathematical sets, like union, intersection, and difference. This example code declares a new set and adds the elements of a second set to it, showing that the updated set contains unique elements:<\/p>"},{"title":"Getting Started with Python Variables","link":"https:\/\/www.linode.com\/docs\/guides\/python-variables\/","pubDate":"Tue, 04 Apr 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-variables\/","description":"<p>Variables are what make programs capable of meaningful action and complexity. Understandably, you want to know how they work for any language you are working with.<\/p>"},{"title":"Stack in Python: A Practical Guide to Getting Started","link":"https:\/\/www.linode.com\/docs\/guides\/python-stacks\/","pubDate":"Tue, 04 Apr 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-stacks\/","description":"<p>Stacks are convenient data structures, collecting items in a last-in-first-out order like you see with many activity histories. But you may be wondering how exactly stacks work. Or you may be curious how you can start implementing a stack in Python.<\/p>"},{"title":"The Basics of Python Data Types","link":"https:\/\/www.linode.com\/docs\/guides\/python-data-types\/","pubDate":"Tue, 04 Apr 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-data-types\/","description":"<p>Knowing about Python&rsquo;s data types helps to make your Python programs more effective, and helps you to avoid errors. This guide covers the most useful Python data types, providing knowledge of their fundamentals and giving a cheat sheet that you can refer to.<\/p>"},{"title":"How to Write and Run a Python Script","link":"https:\/\/www.linode.com\/docs\/guides\/how-to-write-and-run-python-script\/","pubDate":"Mon, 03 Apr 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/how-to-write-and-run-python-script\/","description":"<p><a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > is one of the most popular programming languages due to its ease of use and a large selection of built-in features. This guide describes the basic concepts behind Python, including how to install and use Python modules. It also explains how to write and run a Python script.<\/p>"},{"title":"How to Use Unicode in Python 3","link":"https:\/\/www.linode.com\/docs\/guides\/how-to-use-unicode-in-python3\/","pubDate":"Mon, 20 Mar 2023 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/how-to-use-unicode-in-python3\/","description":"<p>Most of the time, using <a\n href=\"https:\/\/home.unicode.org\/\"\n \n target=\"_blank\"\n \n ><em>Unicode<\/em><\/a\n > characters in Python does not require extra effort. However, sometimes encoding and decoding do not work properly, which results in errors. To resolve these issues, this guide helps you understand how Python encodes and decodes Unicode. Fortunately, the Python library includes some powerful and useful utilities and built-in functions to manage these tasks. This guide introduces Unicode and the <a\n href=\"https:\/\/en.wikipedia.org\/wiki\/UTF-8\"\n \n target=\"_blank\"\n \n ><em>UTF-8<\/em><\/a\n > character encoding and explains how Python handles Unicode. It also discusses some common Python Unicode errors and demonstrates how to resolve them.<\/p>"},{"title":"Lua vs Python: Which One is Right for You?","link":"https:\/\/www.linode.com\/docs\/guides\/lua-vs-python\/","pubDate":"Fri, 30 Dec 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/lua-vs-python\/","description":"<p>Lua and Python are often mentioned as good choices for embedded scripting languages. Both are interpreted, dynamically typed programming languages implemented in C. Both support procedural, object-oriented, and functional programming. Both are easy to learn compared to compiled, strongly typed, non-garbage-collected languages. This guide explores each language and the differences between them, so you can choose which is a better fit for your applications.<\/p>"},{"title":"Check Your Python Version","link":"https:\/\/www.linode.com\/docs\/guides\/check-python-version\/","pubDate":"Mon, 15 Aug 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/check-python-version\/","description":"<p>Python reigns as one of the most popular programming languages, with a wide range of programs and developer tools relying on it. In fact, your system likely already has at least one version of Python installed.<\/p>"},{"title":"Use Python-Markdown to Convert Markdown to HTML","link":"https:\/\/www.linode.com\/docs\/guides\/how-to-use-python-markdown-to-convert-markdown-to-html\/","pubDate":"Thu, 21 Jul 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/how-to-use-python-markdown-to-convert-markdown-to-html\/","description":"<p>The <a\n href=\"https:\/\/en.wikipedia.org\/wiki\/Markdown\"\n \n target=\"_blank\"\n \n ><em>Markdown<\/em><\/a\n > markup language is a good choice for text formatting. Unfortunately, the Markdown syntax does not align with HTML conventions. Without further modification, Markdown can only be shared as plain text. The <a\n href=\"https:\/\/python-markdown.github.io\/index.html\"\n \n target=\"_blank\"\n \n ><em>Python-Markdown<\/em><\/a\n > library is an open source Python module that converts Markdown text into standards-compliant HTML markup. This guide explains how to install and use the Python-Markdown module and provides some background information about it.<\/p>"},{"title":"Python Arrays: What They Are and How to Use Them","link":"https:\/\/www.linode.com\/docs\/guides\/python-arrays\/","pubDate":"Fri, 17 Jun 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-arrays\/","description":"<p>Python arrays provide an effective way to store multiple values of the same type in a single variable. In this tutorial, you learn what Python arrays are and how to use them, and the difference between Python lists and arrays. You also learn how to loop through an array, add and remove elements from an array, and how to combine the values stored in different arrays.<\/p>"},{"title":"The Priority Queue in Python 3","link":"https:\/\/www.linode.com\/docs\/guides\/python-priority-queue\/","pubDate":"Fri, 17 Jun 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-priority-queue\/","description":"<p>In Python, queues are frequently used to process items using a <em>first in first out<\/em> (FIFO) strategy. However, it is often necessary to account for the priority of each item when determining processing order. A queue that retrieves and removes items based on their priority as well as their arrival time is called a <a\n href=\"https:\/\/en.wikipedia.org\/wiki\/Priority_queue\"\n \n target=\"_blank\"\n \n ><em>priority queue<\/em><\/a\n >. Prioritization can be complicated, but fortunately Python priority queues can be easily and efficiently implemented using a built-in module. This guide introduces the Python priority queue and explains how to implement it in Python 3.<\/p>"},{"title":"Convert Data Types in Python","link":"https:\/\/www.linode.com\/docs\/guides\/how-to-convert-datatypes-in-python\/","pubDate":"Fri, 03 Jun 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/how-to-convert-datatypes-in-python\/","description":"<p>Python is a dynamically typed language, so programmers might not always consider the type of each variable they create. However, the type of a variable is often important, and it might be necessary to convert it to another data type. This guide explains how typecasting works and illustrates how to convert data types in Python. It covers several common examples, such as how to convert an integer to a string.<\/p>"},{"title":"Python String Interpolation","link":"https:\/\/www.linode.com\/docs\/guides\/python-string-interpolation\/","pubDate":"Fri, 20 May 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-string-interpolation\/","description":"<p>During <em>string interpolation<\/em> a string literal is evaluated and if any placeholders are present, they are substituted by the indicated variable values. String interpolation helps reduce repetition in code and allows for dynamic string substitution. Python string interpolation consists of two parts: a <em>string template<\/em> and a value, or set of values, that you want to place within that template. To trigger string interpolation, the compiler needs some method of determining where to place the values within the string template. Python provides four techniques to do this, and this guide covers them all. Each string interpolation technique has its own advantages and disadvantages. The four ways to trigger string interpolation are the following:<\/p>"},{"title":"Reverse a String in Python","link":"https:\/\/www.linode.com\/docs\/guides\/how-to-reverse-a-string-in-python\/","pubDate":"Fri, 13 May 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/how-to-reverse-a-string-in-python\/","description":"<p>Python supports several common string operations, like <a\n href=\"https:\/\/www.linode.com\/docs\/guides\/how-to-slice-and-index-strings-in-python\/\"\n \n >slicing, indexing, searching,<\/a\n > and <a\n href=\"https:\/\/www.linode.com\/docs\/guides\/string-manipulation-python-3\/\"\n \n >advanced formatting<\/a\n >. However, it lacks a dedicated, built-in method for reversing strings. This guide shows you how to reverse a string in Python by leveraging Python&rsquo;s tools for working with sequences.<\/p>"},{"title":"Use Dictionaries in Python 3","link":"https:\/\/www.linode.com\/docs\/guides\/python-3-dictionaries\/","pubDate":"Fri, 01 Apr 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-3-dictionaries\/","description":"<p>A dictionary in Python is much like the dictionary you find online or the paper version you find on a shelf. It consists of a series of key-value pairs. A Python dictionary&rsquo;s keys are used to retrieve a dictionary entry along with its value. The act of assigning a key to a value is called <em>mapping<\/em>, so a Python dictionary is a <em>mapped data type<\/em>. This guide introduces you to the Python 3 dictionary data type and shows you how to use dictionaries in your Python code.<\/p>"},{"title":"The Pros and Cons of Python Programming","link":"https:\/\/www.linode.com\/docs\/guides\/pros-and-cons-of-python\/","pubDate":"Wed, 23 Mar 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/pros-and-cons-of-python\/","description":"<p><a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > is currently one of the world&rsquo;s most popular programming languages. It achieved this position due to its powerful features, flexibility, and ease of use. This guide explains the pros and cons of Python and compares it to other languages. It also discusses the situations where Python is one of the best alternatives.<\/p>"},{"title":"An Introduction to Python Tuples","link":"https:\/\/www.linode.com\/docs\/guides\/python-tuples\/","pubDate":"Fri, 25 Feb 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-tuples\/","description":"<p>A tuple is a built-in Python data structure that stores multiple comma-separated values. Tuples are an immutable <em>sequence<\/em> type that can store values of any data type. A mix of different data types can also be stored in a tuple. This guide describes the characteristics of tuples and shows you the various ways you can create a Python tuple.<\/p>"},{"title":"Boolean Variables, Operators, and Conditional Statements in Python","link":"https:\/\/www.linode.com\/docs\/guides\/boolean-variables-in-python\/","pubDate":"Fri, 04 Feb 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/boolean-variables-in-python\/","description":"<p><em>Boolean logic<\/em> is at the heart of <a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > and most programming languages. It allows programmers to make comparisons, execute conditional statements, and implement common algorithms. The &ldquo;greater than&rdquo; (<code>&gt;<\/code>) and &ldquo;equals to&rdquo; (<code>==<\/code>) symbols are examples of Python comparison operators, while <code>and<\/code> and <code>or<\/code> are some of Python&rsquo;s logical operators. This tutorial explains Boolean logic and expressions and discusses how to use Python&rsquo;s Boolean operators.<\/p>"},{"title":"For and While Loops in Python 3","link":"https:\/\/www.linode.com\/docs\/guides\/python-for-and-while-loops\/","pubDate":"Fri, 04 Feb 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-for-and-while-loops\/","description":"<p>Programs often have to run the same commands over and over again. <a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > provides two types of loop statements to handle two different situations. The Python <code>for<\/code> loop is used when the number of iterations is known before the loop starts running. In contrast, the Python <code>while<\/code> loop repeats as long as a certain condition is true. This tutorial describes how to use both types of loops and explains how to use Python for common scenarios like looping through a dictionary.<\/p>"},{"title":"If Statements and Chained Conditionals in Python 3","link":"https:\/\/www.linode.com\/docs\/guides\/if-statements-and-conditionals-in-python\/","pubDate":"Fri, 04 Feb 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/if-statements-and-conditionals-in-python\/","description":"<p><a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > programs must be able to run different branches of code in different situations. This is usually accomplished through the use of <em>conditional statements<\/em>, which determine the <em>control flow<\/em> through a program. Python&rsquo;s <code>if<\/code> statement is used to decide whether or not some code should run. This guide explains the <code>if<\/code> statement and other Python conditionals and demonstrates how to use them.<\/p>"},{"title":"Install and Import Modules in Python 3","link":"https:\/\/www.linode.com\/docs\/guides\/installing-and-importing-modules-in-python-3\/","pubDate":"Fri, 28 Jan 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/installing-and-importing-modules-in-python-3\/","description":"<p>Except for very short and simple programs, most <a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > applications contain code from many files, directories, and packages. Related functions and attributes are often grouped together as part of a Python <em>module<\/em>. A programmer can <em>import<\/em> this module and use its functions and variables in their application. This guide provides an introduction to Python modules and explains how to install and import modules in Python.<\/p>"},{"title":"Slicing and Indexing Strings in Python","link":"https:\/\/www.linode.com\/docs\/guides\/how-to-slice-and-index-strings-in-python\/","pubDate":"Fri, 28 Jan 2022 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/how-to-slice-and-index-strings-in-python\/","description":"<p><a\n href=\"https:\/\/www.python.org\/\"\n \n target=\"_blank\"\n \n >Python<\/a\n > has become one of the world&rsquo;s most popular programming languages due to its intuitive and straightforward nature. Among its attractive features is a powerful library for parsing and processing string objects. Python provides tools for indexing strings and creating substrings from larger strings, which is known as <em>slicing<\/em>. This tutorial discusses how to use Python string indexing and how to slice a string in Python.<\/p>"},{"title":"Use Mypy for Python Static Type Checking","link":"https:\/\/www.linode.com\/docs\/guides\/python-static-type-checking-with-mypy\/","pubDate":"Fri, 10 Dec 2021 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-static-type-checking-with-mypy\/","description":"<p>Python is a dynamically typed language. It determines data types at run time, rather than compile time. Some examples of Python types include integers, floats, strings, and boolean. Dynamically typed languages stand in contrast to statically typed languages, like C++, Java, and Fortran, that perform type checking at compile time.<\/p>"},{"title":"An Introduction to Mock Testing Using the Python Unittest Library","link":"https:\/\/www.linode.com\/docs\/guides\/mock-testing-using-the-python-unittest-library\/","pubDate":"Fri, 03 Dec 2021 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/mock-testing-using-the-python-unittest-library\/","description":"<p>The Python unittest library helps you test your application code for errors in an automated way. It\u2019s one of the testing methods discussed in our guide, <a\n href=\"https:\/\/www.linode.com\/docs\/guides\/python-testing-frameworks-for-software-unit-testing\/#unittest-python-testing-framework-example\"\n data-turbolinks=\"false\"\n >An Overview of Python Testing Frameworks for Unit Testing<\/a\n >. Mock testing is especially useful while your code is yet to be completed and your development is progressing. It performs continuous testing during development and provides good insights into how an application might ultimately function. This guide shows you how to use the Python unittest library to create mock objects to test your code.<\/p>"},{"title":"Python in ML: Why You Should Use Python for Machine Learning","link":"https:\/\/www.linode.com\/docs\/guides\/python-ml\/","pubDate":"Fri, 03 Dec 2021 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/python-ml\/","description":"<p><em>Artificial Intelligence<\/em> (AI), the appearance or simulation of human intelligence within a machine, is popular today because it can solve a huge number of problems within specific categories using well-known algorithms. Machine Learning (ML) is a sub-category of AI that depends on large datasets to affect the computations of algorithms to allow a generalized result that an application can apply to unseen data. In other words, ML provides an experience-based method to use AI techniques to solve problems realistically. Python ML features handle the required amounts of data effectively, and offer access to a broad range of algorithms using libraries like scikit-learn and SciPy to solve the various ML problem categories. Python\u2019s capabilities deliver in a manner that is understandable in AI Python code, and which reduces the learning curve that most developers face.<\/p>"},{"title":"The Top 9 Web Development Languages You Need To Know","link":"https:\/\/www.linode.com\/docs\/guides\/web-programming-languages\/","pubDate":"Wed, 24 Nov 2021 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/web-programming-languages\/","description":"<p>Web development began as a process for structuring static content using HTML to make it easier to exchange. Adding style with CSS came next so that a web page could provide appealing content. These web pages were static and people wanted more. Web development is well beyond these simple beginnings today. Sometimes it\u2019s hard to know when you\u2019re using a web application or a desktop application, or a combination of the two. There are so many possibilities for content and presentation that it\u2019s hard to know what to choose in the way of web programming languages. However, if you review what you want to do and why you want to do it, the choice of web programming languages quickly diminishes. The website programming language you choose affects what sorts of web design coding you can do.<\/p>"},{"title":"Install PyTorch on Ubuntu 20.04","link":"https:\/\/www.linode.com\/docs\/guides\/pytorch-installation-ubuntu-2004\/","pubDate":"Fri, 05 Nov 2021 00:00:00 +0000","guid":"https:\/\/www.linode.com\/docs\/guides\/pytorch-installation-ubuntu-2004\/","description":"<p>This guide shows you how to install <a\n href=\"https:\/\/pytorch.org\/\"\n \n target=\"_blank\"\n \n >PyTorch<\/a\n >, a Python framework, on an Ubuntu 20.04 Linode. PyTorch provides support for a variety of math-intensive applications that run on GPU and CPU hardware. Linode offers dedicated <a\n href=\"https:\/\/www.linode.com\/products\/dedicated-cpu\/\"\n \n target=\"_blank\"\n \n >CPU instances<\/a\n > and <a\n href=\"https:\/\/www.linode.com\/products\/gpu\/\"\n \n target=\"_blank\"\n \n >GPU instances<\/a\n > that you can use to run PyTorch-based projects.<\/p>"}]}}