Sat. Feb 4th, 2023

Category: Python

Python f strings

PEP 498 introduces a new kind of string literals: f-strings, or formatted string literals. Formatted string literals are prefixed with 'f' and are similar to the format strings accepted by str.format(). They contain replacement fields surrounded…

Python Virtual Environment (venv)

The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the…

Python – Help and Docstrings

In this tutorial we have used help() a few times. It’s great and you can use it as much as you want to. For example, running help(str) displays a nice list of all string…

Python – Exceptions

So far we have made programs that ask the user to enter a string, and we also know how to convert that to an integer. text = input("Enter something: ")…

Python – Modules

Let’s say we want to generate a random number between 1 and 3. The random module is a really easy way to do this: >>> import random >>> random.randint(1, 3)…

Python – Managing files in Python

What are files, directories and paths? These are simple thing that many computer users already know, but I’ll go through them just to make sure you know them also. Files…

Python – What is true?

Now we understand how code like this works. message = input("Enter something: ") if message == '': print("You didn't enter anything!") else: print("You entered:", message) But most Python programmers would…

Python – Writing a larger program

Now we know enough about Python for creating a program that is actually useful. Awesome! In this tutorial we’ll write a program that reads questions and answers in a text…