Identifiers in Python: Rules, Examples and isidentifier()

Identifiers in Python: isidentifier() output for eight column headers

A name like total_sales or Customer is what Python calls an identifier: the label you give a variable, function, class or module. It has to start with a letter or underscore, use only letters, digits and underscores after that, and it can’t be a keyword. To test a string against those rules, call isidentifier(): In … Read more >>

How to Check if a String is ASCII in Python

Check if a string is ASCII in Python: isascii() output for six customer names

Say you’re sending customer names from a Chicago shop to a label printer that only takes ASCII. To check if a string is ASCII in Python before it goes out, call name.isascii(). It returns True only if every character is ASCII (0-127). In this tutorial, we’ll walk through four ways to check if a string … Read more >>

Maximum Value of int in Python (sys.maxsize Explained)

Maximum value of int in Python: Command Prompt output showing unlimited integers and sys.maxsize

There’s no maximum value of int in Python 3: integers grow as large as your memory allows. What people often mean is sys.maxsize, which is 9,223,372,036,854,775,807 (2**63 – 1) on 64-bit systems, the largest size a list or string can report: All the limits below were printed by Python 3.12.5 with NumPy 2.5.3 on 64-bit … Read more >>

What Is the Best Way to Learn Python? (A 6-Week Plan)

Best way to learn Python: a first tip-splitter script and its output in Command Prompt

Two coworkers asked me this month for the best way to learn Python. Each had watched about ten hours of a video course and still couldn’t write a ten-line script without pausing the video. That’s the most common way people stall. Watching someone else code feels like progress, but your fingers never learn the syntax. … Read more >>

PyCharm vs VS Code for Python: Which Should You Use?

PyCharm vs VS Code for Python: an invoice script running in the VS Code integrated terminal

If you’re choosing between PyCharm and VS Code for your first real Python project, you’re probably worried about picking wrong. You won’t break anything either way, because both run the same Python and the same files. My verdict: start with VS Code if you also write JavaScript or SQL, or want one free editor for … Read more >>

Python Dictionary Count: How to Count Items With a Dict

Python dictionary count: output of a get() loop counting ten coffee orders by drink

To do a Python dictionary count, loop over your data with counts[item] = counts.get(item, 0) + 1, or pass the whole list to collections.Counter. Either way, each key holds how often it showed up. In this tutorial, we’ll build a Python dictionary count three ways, then count the values already inside a dict. I tested … Read more >>

Python 3 vs Python 2: Key Differences and Which to Use

Python 3 vs Python 2: Command Prompt output of integer division and round() in Python 3

Python 3 vs Python 2 usually comes up when an inherited script, an old tutorial or a server with python2 on it refuses to cooperate, not when you’re picking a language for a new project. So here’s my rule: use Python 3 for everything you write or run today. Only open Python 2 to read … Read more >>

How to Remove NaN Values from a List in Python (5 Ways)

Python list comprehension removing NaN values from a list of daily USD sales in Command Prompt

A store manager I work with loaded one week of daily online sales into a Python list from a broken export. Two values came through as NaN, so her weekly total printed nan instead of a dollar amount. Her first fix was x != float(“nan”), which removes nothing, because NaN never equals anything, not even … Read more >>

What Is an Interpreter in Python? (How Python Runs Code)

What is an interpreter in Python: an interactive Python REPL session in Command Prompt

So what is an interpreter in Python? It’s the program that reads your Python code and runs it. When you type python script.py, the interpreter (usually CPython) compiles the code to bytecode and executes it right away, with no separate build step: The screenshots show Python 3.12.5 on Windows, including an interactive session I typed … Read more >>