Python program to count files inside a folder

November 3, 2020 A Goodman

The Python program below counts the number of files inside a folder. Program folder structure: Note that the photos folder contains 11 files and 1 empty folder named empty. The code and explanation: Output:

Python: Count words in a string using Regular Expression

November 3, 2020 Guest Contributor

The Python program below counts the number of words in a given string. Whitespace and any special symbols except the underscore will be ignored. Output:

5 essential List Methods in Python 3

February 9, 2021 A Goodman

List is an extremely important datatype in Python and you will work with it a lot when building programs. It is not necessary to memorize all List methods in Python, but mastering the most popular methods…

How to deep copy a List in Python

January 29, 2021 A Goodman

To copy a list in Python (not just copy its reference), you can use the deepcopy method of the copy module Example The code: Output:

Python: Generate a random integer between Min and Max

October 29, 2020 A Goodman

To generate a random integer between two given integers, you can use the randint method of the random module. Example Hope this helps 🙂

5+ Python For Loop examples

October 29, 2020 A Goodman

A few examples of the For loop in Python. Print all the divisible-by-x numbers from 0 to n a) Print all the divisible-by-3 numbers from 0 to 100: Output: b) Print all the divisible-by-7 numbers from…

Python: Calculate Fibonacci number with 4 lines of code

October 29, 2020 A Goodman

The Fibonacci numbers Fibonacci numbers with Python Reminder: Python accepts function recursion, which means a defined function can call itself. With only 4 lines of Python code, we can write a program that calculates the n-th…

Python: Sum integers from 1 to N the easiest way

October 24, 2020 Guest Contributor

This’s a short and straight to the point guide to calculating the sum of integers from 1 to n in Python. The code: Output:

Check Python versions on Mac

October 23, 2020 A Goodman

To check Python 2 version in macOS, use: Output (your version may be higher or lower a little bit): To see the exact version of Python 3 in macOS, use: Output (your version may be higher…

How to run Python 3 with Nodemon on Mac

October 23, 2020 A Goodman

Python 2 is pre-installed in macOS, thus when you try to run your Python code with Nodemon like this: then Python 2 starts its job. If you want to use Python 3 instead, run this command:…

Python if/else/elif examples

June 20, 2020 A Goodman

A few examples of how to use if/else/elif statements in Python. Important notes: Unlike other programming languages, Python doesn’t use brackets to separate block of code execution statements. Instead, it uses whitespace. The keyword ‘elif’ is…

Python Hello World with VS Code

June 19, 2020 A Goodman

In this short article, you will learn how to write your first lines of Python code and run them with the built-in terminal of the VS Code. Prerequisites: Make sure Python and VS Code already installed…

1 2 3 4