Most popular String methods in Python

November 27, 2020 Ken Fisher

Python provides a lot of methods that help programmers easily and quickly modify and manipulate strings. Learning all of these methods by heart is a hard job that takes much time and effort, and you may…

Python3.9 malloc error: can’t allocate region

November 23, 2020 Goodman

Problem When running Python code that imports some modules (request, numpy, pandas, etc), I fall into the following error: This happens with both global and virtual environment. More error messages: My environment: Solution If you run…

Python program to count lower case letters in a string

November 4, 2020 Anonymous

To check if a letter is lower case or not in Python, we can use the islower() method. Combine it with a for loop, we can easily count the number of lower case letters in a…

Python program to count all capital letters in a string

November 4, 2020 Anonymous

The following Python program counts the number of capital letters in a string. The code: Output: That’s it. Happy coding with Python πŸ™‚

Python program to count files inside a folder

November 3, 2020 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 Anonymous

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

October 29, 2020 Goodman

Most common methods when working with lists in Python. The index() method This method returns the index of an item in the list. Example: Output: Th sort() method This method sorts the items in a list….

How to deep copy a list in Python

October 29, 2020 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 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 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 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 Anonymous

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 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 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 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 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…