Home » Search results for 'python string'

Multi-Line Comment Blocks in Python – HowTo, With Examples

Python multi-line comment block

This short article will show you how to use comments in Python, including multi-line comments. What is a Comment? A comment in programing is one or more lines of text that aren’t interpreted as programming instructions. Instead, the computer skips them when executing your code, completely ignoring them. Therefore, comments don’t have to conform to any valid syntax. They’re just text that you read, and the computer doesn’t. Single-Line Comments in Python Comments in Python are any line that starts with a # (hash) character. # This … Read more

Home » Search results for 'python string'

Catch Errors/Exceptions in Python with try/except [Examples]

Python try/except to Catch Errors

This article will show you how to use the try/except/finally statements. What are Errors/Exceptions A computer program will produce an error, also known as an exception, when something goes wrong. This could be due to mistyped programming commands (syntax errors) or because the application encountered something unexpected – be it bad user input or a logical condition that can’t be met. When something goes wrong, an exception/error will be thrown – which will usually result in the application stopping and the error being displayed so that it can be found and fixed. … Read more

Home » Search results for 'python string'

Enums in Python – What They Are, How to Use Them

Python Enum

This article will teach you what an Enum is, and how they are used in the Python programming language. What is an Enum? An Enum (Enumerated Type) is a data structure containing multiple values. Each value is assigned to an identifier – and can be accessed by that identifier. Enums contain pre-defined constants that aren’t expected to change (they’ll be the same when the application is written and when it is run so that you can always refer to the data in the enum by the same identifier and get … Read more

Home » Search results for 'python string'

How to Use ‘for’ Loops in Python, With Examples

Python for Loops

This article will show you how to use for loops in Python 3 and provide examples. Loops are one of the fundamentals of programming. So you’ll use them almost constantly. Data in computer software is often stored in arrays (or lists), for example, a record of students enrolled in a course, with each item in a list representing a student. These arrays of data need to be processed – and this is done using loops that step through each item in the array and perform some … Read more

Home » Search results for 'python string'

Python lstrip and rstrip Methods – With Examples

Python lstrip and rstrip Methods

This short tutorial will show you how to use lstrip and rstrip to remove whitespace (or any other characters) from the beginning/end of strings in Python. The lstrip and rstrip methods are available on any string type variable in Python 3. Python lstrip String Method The lstrip (Left strip) method will remove leading characters from the string – that is, characters starting from the left of the string. Syntax Here’s the syntax for the lstrip method: string.lstrip(characters) Note that: string can be any string value or variable with a string value characters is an optional parameter for the lstrip method These are the characters that … Read more

Home » Search results for 'python string'

Appending Items to a List in Python with append() [Examples]

Python - Append to List

This article will show you how to add items to a list in Python using the append() method. Lists are a type of Python variable that can hold any number of member elements. They’re analogous to arrays in other programming languages. Lists can be defined and altered in several ways: Using the Python ‘filter()’ Function to Filter a List, with Examples Using the Python ‘map()’ Function to Process a List, With Examples Python List ‘sort()’ Method – Sorting Lists in Python Easily How to Reverse a List in … Read more

Home » Search results for 'python string'

Converting Variable Types in Python, Howto, With Examples

Python Type Conversion

This article will show you how to use Python’s built-in variable conversion functions, with examples. A variable’s type determines what kind of data it can store and what can be done with it. For example, string typed variables contain sequences of characters that can be joined and split (think words and sentences). In contrast, numeric typed variables contain numeric values intended to be used in calculations. Being able to convert a variable’s type allows data to be used in different ways. Converting a Variable to a … Read more

Home » Search results for 'python string'

Linked Lists in Python – How to Use Them, With Examples

Python Linked Lists

This article will explain in simple terms what linked lists are, why they’re useful, and how to use them in the Python programming language. Lists In Python, a list is an array of data – a simple list of values where each item has a value and a position in the list. Lists are indexed (so the positions start counting at position 0, not 1). For more information on lists in Python, check out these LinuxScrew articles: Python List ‘sort()’ Method – Sorting Lists in Python Easily … Read more

Home » Search results for 'python string'

Command Line Arguments in Python Scripts, With Examples

Python Command Line Arguments

This article will show you simple methods to pass command line arguments to your Python scripts, with some examples. Passing arguments to your script makes it easy to build multi-use scripts that can work on different inputs. This is much easier than re-editing your code every time you want to change the inputs it will be working on. I’ve previously covered building a full command-line application in Python, which accepts command-line options and bundles the application into a distributable package with no external dependencies – … Read more

Home » Search results for 'python string'

DIY Raspberry Pi/Python Powered PACHINKO [Kitchen Build]

Raspberry Pi Python Pachinko

Pachinko? Pichinko? Pychinko? I’ve been playing around with is idea for a while because… I don’t know; it seemed like a cool concept. That’s my whole motivation. Here’s a Raspberry Pi and Python-powered pachinko machine. This project is really basic, so it’s good for beginners, and the result is a lot of fun to mess with and would make a good desk ornament to fidget with or something for the kids to build on a rainy day to learn about coding and circuits and all … Read more