7 Sources of Passive Income for Coders

These are the types of passive income:

Affiliate earningsAdvertising earningseBooksOnline coursesSaaSIndex funds and exchange-traded funds (ETFs)Real estate

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn

Continue reading the original article

Python One Line Return if

Problem: How to return from a Python function or method in single line?

Example: Consider the following “goal” statement:

def f(x):
return None if x == 0

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 three methods in the interactive code shell:

Exercise: The code has no output. Print the results of all three function executions for a given x. Is it always the same?

Let’s dive into the three methods.

Method 1: As a Multi-Liner

The following

Continue reading the original article

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 by hackers to gain access to a target machine. The target machine opens a shell to communicate to the attacking machine. The attacking machine receives the connection (listening on a given port) and is now able to access the target computer. To accomplish a reverse shell, a hacker

Continue reading the original article

How to Execute Multiple Lines in a Single Line Python From Command-Line?

Summary: To make a Python one-liner out of any multi-line Python script, replace the new lines with a new line character ‘n’ and pass the result into the exec(…) function. You can run this script from the outside (command line, shell, terminal) by using the command python -c “exec(…)”.

Problem: Given a multi-line code script in Python. How to execute this multi-line script in a single line of Python code? How to do it from the command line?

Example: Say, you have the following for loop with a nested if statement in the for loop body. You want to run this

Continue reading the original article

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 been a discussion about one-line exception handling on the official Python mailing list in 2013. However, since then, there has been no new “One-Line Exception Handling” feature in Python. So, we need to stick with the methods shown in this tutorial. But they will be fun—promised!

Continue reading the original article

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’):

with open(‘code.py’) as code:

The output of this code would be the code itself (for nerds: a piece of code that generates itself is called a Quine):

with open(‘code.py’) as code:


No matter what goes wrong inside the with block, Python will close the open file before moving on in the code. This way, you don’t need to enclose the

Continue reading the original article

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.


What is the input? (file, file type, email, text,…) File with list of email addresses (one per line)What is the output? (file, file type, text, csv, …) File with all email addresses that are from a disposable email provider:https://gist.github.com/michenriksen/8710649Where does the input come from? (user input from the console, specific path,…) How should the input be processed? Where should

Continue reading the original article

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:

What is a Quine?

Roughly speaking, a quine is a self-reproducing program: if you run it, it generates itself.

Here’s a great definition:

:quine: /kwi:n/ /n./ [from the name of the logician Willard van Orman Quine, via Douglas Hofstadter] A program that generates a copy of its own source text as its complete output. Devising the shortest possible quine in some given programming language is a common hackish amusement. (source)

The name “quine” was coined by Douglas Hofstadter, in his popular

Continue reading the original article

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.

How to Write a While Loop in a Single Line of Python Code?

There are three ways of writing a one-liner while loop:

Method 1: If the loop body consists of one statement, write this statement into the same line: while True: print(‘hi’). This prints the string ‘hi’ to the shell for as long as you don’t interfere or your operating

Continue reading the original article

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 array b with all values of a—while adding +1 to each value. Here’s your multi-liner:

a = [1, 2, 3, 4]
b = []
for x in a:
# [2, 3, 4, 5]

How do you accomplish this in a single line of code?

Answer: No, you don’t need a lambda

Continue reading the original article