[Collection] All Finxter Articles and Tutorials

7 Sources of Passive Income for Coders

These are the types of passive income: Affiliate earnings Advertising earnings eBooks Online courses SaaS Index funds and exchange-traded funds (ETFs) Real estate Related posts: [Summary] Independent Work: Choice, Necessity, and the Gig Economy Upwork vs Fiverr: What Every Developer Ought to Know Python Freelancing: My First Fiverr Gig and How I Solved It 3

​Read More

Python One Line Return if

Problem: How to return from a Python function or method in single line? Example: Consider the following “goal” statement: However, this leads to a Syntax error: In this tutorial, you’ll learn how to write the return statement with an if expression in a single line of Python code. You can get an overview of the

​Read More

Python One Line Reverse Shell

This article will be fun! You’ll learn about an important concept in security: reverse shells. You’ll also learn how to create reverse shells in Python in a single line of code. So, let’s start with the big question: What is a Reverse Shell? Here’s the definition of a Reverse Shell: A reverse shell is used

​Read More

Python One Line Exception Handling

Summary: You can accomplish one line exception handling with the exec() workaround by passing the one-linerized try/except block as a string into the function like this: exec(‘try:print(x)\nexcept:print(“Exception!”)’). This general method works for all custom, even multi-line, try and except blocks. However, you should avoid this one-liner code due to the bad readability. Surprisingly, there has

​Read More

3 Passive Income Ideas on Upwork or Fiverr

The following three ideas can lead to passive income using Upwork or Fiverr: Hire experts in their niches on Upwork or Fiverr to create online courses and sell them on Udemy Hire experts in their niches on Upwork or Fiverr to create ebooks and sell them on Amazon Hire freelance developers on Upwork or Fiverr

​Read More

Python One Line With Statement

The with statement replaces former try…finally blocks in Python. It ensures that clean-up code is executed. For example, it closes open files before leaving the block. Consider this code example (assuming this code is stored in a file named ‘code.py’): The output of this code would be the code itself (for nerds: a piece of

​Read More

Python One Line Quine

Most computer scientists, programmers, and hackers don’t even know the meaning of the word “Quine” in the context of programming. So, first things first: Table of Contents What is a Quine?Python One-Liner Quine 1Python One-Liner Quine 2Python One-Liner Quine 3Python One Liner Quine 4Where to Go From Here? What is a Quine? Roughly speaking, a

​Read More

What is __init__ in Python?

When reading over other people’s Python code, many beginners are puzzled by the __init__(self) method. What’s its purpose? This article answers this question once and for all. What’s the purpose of __init__(self) in Python? The reserved Python method __init__() is called the constructor of a class. You can call the constructor method to create an

​Read More

What’s the Hourly Rate of a Python Freelancer?

$56/hour How much can you expect to earn as a Python freelancer?   The average Python developer worldwide earns $56 per hour (fluctuations between $51 and $61). This statistic is based on five credible online sources including the US government. In the US, the average Python developer earns $60 per hour or more. Based on

​Read More

How to Earn Passive Income as a (Python) Coder?

Finxter is at the intersection of programming, business, and productivity so we get this question a lot. In this article, I want to share three ideas on how you can invest one or two weeks coding which will then produce passive income for years to come. Definition: You create a software product or website once

​Read More

Python Freelancing: My First Fiverr Gig and How I Solved It

Basic Webscraping Script in Python | Requests | BeautifulSoup | ArgParse Sold Gig ($35) This is the gig description I offered on my profile to get my first gig: An email marketing company hired me to write a Python script that satisfies the following requirements. Requirements What is the input? (file, file type, email, text,…)

​Read More

NumPy arccos()

The NumPy arccos() function is the trigonometric inverse cosine function so that, if y = cos(x), then x = arccos(y). If you apply it to a NumPy array, it performs the function element-wise. Arguments Type Description x array_like x-coordinate on the unit circle. For real arguments, the domain is [-1, 1]. out ndarray, None, or

​Read More

Python One Line While Loop [A Simple Tutorial]

Python is powerful — you can condense many algorithms into a single line of Python code. So the natural question arises: can you write a while loop in a single line of code? This article explores this mission-critical question in all detail. Table of Contents How to Write a While Loop in a Single Line

​Read More

Python One Line For Loop Lambda

Problem: Given a collection. You want to create a new list based on all values in this collection. The code should run in a single line of code. How do you accomplish this? Do you need a lambda function? Example: Given an array a = [1, 2, 3, 4]. You need to create a second

​Read More

Python String Replace

A few years ago, the Google company officially renamed to Alphabet. Imagine you’re asked to rename all occurrences of the name “Google” with the occurrences of the name “Alphabet” in internal documents. Would you do it by hand? As a coder, you would automate it! Fortunately, Python’s str.replace() method comes to help to replace occurrences

​Read More

NumPy argpatition()

The NumPy argpatition function performs an indirect partition along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as a that index data along the given axis in partitioned order. Arguments Type Description c array_like or poly1d object The input polynomials to be

​Read More

Upwork vs Fiverr: What Every Developer Ought to Know

The landscape of work undergoes a major disruption. More and more work is delivered online. And who are the biggest winners? The stakeholders of the top freelancing platforms: Upwork and Fiverr: Stockholder who own Upwork and Fiverr, Employees working for Upwork and Fiverr, Freelancers offering their services on Upwork and Fiverr, and Business owners who

​Read More

Python One Line For Loop With If

This tutorial will teach you how to write one-line for loops in Python using the popular expert feature of list comprehension. After you’ve learned the basics of list comprehension, you’ll learn how to restrict list comprehensions so that you can write custom filters quickly and effectively. Are you ready? Let’s roll up your sleeves and

​Read More

Python One Line For Loop [A Simple Tutorial]

Python is powerful — you can condense many algorithms into a single line of Python code. So the natural question arises: can you write a for loop in a single line of code? This article explores this mission-critical question in all detail. Table of Contents How to Write a For Loop in a Single Line

​Read More

HTML Parsing using Python and LXML

In this article, you’ll learn the basics of parsing an HTML document using Python and the LXML library. Table of Contents IntroductionWhat is the XPath?XPath SelectorXPath SyntaxXPath Functions and OperatorsGoing Up and Down the AxisA Simple Example Introduction Data is the most important ingredient in programming. It comes in all shapes and forms. Sometimes it

​Read More

Python One Line If Without Else

Crafting beautiful Python one-liners is as much an art as it is a science. In this tutorial, you’ll learn how to compress an if statement without an else branch into a single line of Python code. Problem: What’s the one-liner equivalent of the simple if statement without an else branch? Here’s an example: You may

​Read More

NumPy polymulx()

The numpy.polymulx function multiplies the polynomial c with a value x which is the independent variable. Arguments Type Description c array_like or poly1d object The input polynomials to be multiplied The following table shows the return value of the function: Type Description Return Value ndarray or poly1d object The polynomial resulting from the multiplication of

​Read More

numpy.polymul

The numpy.polymul function finds the product (multiplication) of two polynomials a1 and a2. As an input, use either poly1d objects or one-dimensional sequences of polynomial coefficients. If you use the latter, arange this polynomial sequence naturally from highest to lowest degree. Arguments Type Description a1, a2 array_like or poly1d object The input polynomials to be

​Read More

The 6 Best Python Easter Eggs

This article compiles a list of little surprises in the Python programming language. Check out the following Instagram post to see them in an interactive mode (swipe right). View this post on Instagram A post shared by The Python Blog (@finxter.com_) on Nov 11, 2019 at 10:35pm PST Here are the best easter eggs: Table

​Read More

Python One-Liner: Write String to File

Problem: Given a string and a filename. How to write the string into the file with filename using only a single line of Python code? Example: You have filename ‘hello.txt’ and you want to write string ‘hello world!’ into the file. How to achieve this? In this tutorial, you’ll learn four ways of doing it

​Read More

numpy.char.capitalize

Original Documentation Return a copy of a with only the first character of each element capitalized. Calls str.capitalize element-wise. For 8-bit strings, this method is locale-dependent. Parameters: a: array_like of str or unicode: Input array of strings to capitalize. Returns: out: ndarray: Output array of str or unicode, depending on input types See also str.capitalize

​Read More

Python Career Paths: How to Learn Python to Get a Job

Let’s be clear: you learn Python to get a job. Sure, coding is a fun, fulfilling hobby. But at the end of the day, we all dream of getting that developer job and finally putting our hard-earned skills to good use earning a comfortable six figure salary: Junior Developer: US Salary $73,537 Software Tester: US

​Read More

Python Ternary Elif

Summary: To use an elif branch in the ternary operator, use another ternary operator as the result of the else branch (nested ternary operator). The nested ternary operator x if c0 else y if c1 else z returns x if condition c0 is met, else if (elif) condition c1 is met, it returns y, else

​Read More

Python Ternary Multiple Lines

What if you have a ternary operator that’s very long? Problem: How to write the ternary operator in multiple lines? Table of Contents Short Recap: Ternary Operator Method: Parenthesis to Extend Logical Line Over Multiple Physical LinesWhere to Go From Here?Related posts: Short Recap: Ternary Operator Ternary Operator: The most basic ternary operator x if

​Read More

Python Ternary Lambda

Problem: How to write the ternary operator in a lambda function? Example: Say, you’ve got the following example: The function f(x) takes one argument x and increases it by 10% if the argument is larger than 100. Otherwise, it increases it by 5%. In this article, you’ll learn how to convert this code snippet into

​Read More

Python Ternary Dictionary

Problem: Given a dictionary and a key. Can you use the ternary operator to return the key from the dictionary, but only if it exists to avoid the key error? If the key doesn’t exist, a “fall-back” function should be executed. Example: Say, you want to do something like the following (pseudocode): Table of Contents

​Read More

The World’s Most Concise Python Cheat Sheet

Do you want to learn Python but you’re overwhelmed and you don’t know where to start? Learn with Python cheat sheets! They compress the most important information in an easy-to-digest 1-page format. Here’s the new Python cheat sheet I just created—my goal was to make it the world’s most concise Python cheat sheet! Related posts:

​Read More

101+ Free Python Books

Spending money on books is one of the best investments you can possibly make. But why should you? This article compiles a list of 101++ FREE Python books to destroy any excuse of not learning Python. Everyone can afford to read free books! Download Your Free PDF with all the links: How To Use This

​Read More

Python Ternary — Tuple Syntax Hack

You may know the ternary operator x if c else y in Python which reads as “return x if c else return y“. But you may not know that you can also write the ternary operator in a shorter form as (y, x)[c]. Let’s dive into this concise way of hacking your own ternary operator!

​Read More

Python One Line Ternary

The most basic ternary operator x if c else y consists of three operands x, c, and y. It is an expression with a return value. The ternary operator returns x if the Boolean expression c evaluates to True. Otherwise, if the expression c evaluates to False, the ternary operator returns the alternative y. Ternary

​Read More

Python One Line Quicksort

In this one-liner tutorial, you’ll learn about the popular sorting algorithm Quicksort. Surprisingly, a single line of Python code is all you need to write the Quicksort algorithm! Problem: Given a list of numerical values (integer or float). Sort the list in a single line of Python code using the popular Quicksort algorithm! Example: You

​Read More

Python One Line X

This is a running document in which I’ll answer all questions regarding the single line of Python code. If you want to become a one-liner wizard, check out my book “Python One-Liners”! 🙂 Let’s get started! Table of Contents Python One Line If ElsePython One Line ElifPython One Line If Without ElsePython One Line FunctionPython

​Read More

How to Create a List of Dictionaries in Python?

Problem: Say, you have a dictionary {0: ‘Alice’, 1: ‘Bob’} and you want to create a list of dictionaries with copies of the original dictionary: [{0: ‘Alice’, 1: ‘Bob’}, {0: ‘Alice’, 1: ‘Bob’}, {0: ‘Alice’, 1: ‘Bob’}]. You use list comprehension with a “throw-away” loop variable underscore _ to create a list of 3 elements.

​Read More

How to Use np.linspace() in Python? A Helpful Illustrated Guide

In this article, I’ll explain the np.linspace function, how to use it and when you should. It has got a bit of a reputation for being complicated but, as you’ll see, it really isn’t! So, let’s get a quick overview first. Syntax: numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0) Argument Default Description start – The

​Read More

Create a List of Random Numbers — The Most Pythonic Way

Do you want to initialize a list with some random numbers? In this article, I’ll show you four different way of accomplishing this—along with a short discussion about “the most Pythonic way”. Problem: Given an integer n. Create a list of n elements in a certain interval (example interval: [0, 20]). Solution: Here’s a quick

​Read More

How to Create a Python List of Size n?

To create a list of n placeholder elements, multiply the list of a single placeholder element with n. For example, use [None] * 5 to create a list [None, None, None, None, None] with five elements None. You can then overwrite some elements with index assignments. In the example, lst[2] = 42 would result in

​Read More

Python SymPy — A Short Primer

What’s SymPy Anyway? SymPy is a Python library for symbolic computation. So instead of approximating the result of the square root of 2, it keeps the square root intact—using a symbolic representation. This helps in further processing and can lead to situations where Python has introduced a floating point precision error without need. Here’s a

​Read More

How to Create a Python List?

Definition Lists: A Python list is an ordered sequence of arbitrary Python objects. It is a mutable object by itself so, unlike Python sets, you can modify a Python list. In this article, you’ll learn everything you need to know on how to create Python lists. Table of Contents Overview — Creating a List in

​Read More

How do you install SymPy in Python?

To install SymPy in Python, simply run the following command in your shell: This works for all major operating systems (MacOS, Windows, Linux). A preliminary is to have the pip package manager installed. (Confused by all the libraries, modules, pip, and virtual environments? Read the ultimate library guide on my blog.) To check whether it

​Read More

Python String to List | The Most Pythonic Way

Programming is a humbling experience. Seemingly simple things will often surprise you, they’re not so trivial after all. One such example is the string to list conversion. In this article, you’ll learn everything you need to know to convert a string to a list—in different contexts and using different methods. Method Description list(string) Break a

​Read More

Lambda Functions in Python: A Simple Introduction

A lambda function is an anonymous function in Python. It starts with the keyword lambda, followed by a comma-separated list of zero or more arguments, followed by the colon and the return expression. For example, lambda x, y, z: x+y+z would calculate the sum of the three argument values x+y+z. Here’s a practical example where

​Read More

Python Tuple to Integer

You have a tuple of integers—but you want a single integer. What can you do? Problem: Given a tuple of values. Your goal is to convert it to a single integer value. There are multiple ways of accomplishing this (dependent on what exactly you want to do). Let’s get a quick overview in our interactive

​Read More

SQLite Python Placeholder – Four Methods for SQL Statements

Are you confusing about SQLite Python Placeholders? It’s time for better understanding! Learn how in this tutorial. Table of Contents IntroductionExamplesQmark Method – Officially RecommendedNamed Method – Officially Recommended%s Method – Traditional, InsecureString Method – Insecure, Sometimes UsefulSummaryReferencesWhere to Go From Here? Introduction SQLite is an embedded open-source relational database engine. Its developers, from SQLite.org,

​Read More

Python List max()

Do you want to find the maximum of a Python list? This article gives you everything you need to know to master the max() function in Python. Description Python’s built-in max() function returns the maximum element of a list or its generalization (an iterable). Syntax The syntax of the max() function is as follows: Arguments

​Read More

What Does “if __name__ == ‘__main__'” Do in Python?

Today, let’s discuss something that’s all over the place in many code bases: what does if __name__ == ‘__main__’ do in Python? The statement if __name__ == ‘__main__’: checks if variable __name__ is set to the string value ‘__main__’ which holds only within the main source file from which you initially execute your code. In all other

​Read More