AskPython
Python Tutorials for Beginners and Experienced Programmers
- Website
- askpython.com · all feeds from this site
- Feed URL
https://www.askpython.com/feed
Read it in your FeedListing reader
Or add to: Feedly Inoreader Raw feed
Latest posts
-
Pandas Read Excel: Load a Workbook
A Python analysis can start with the values stored in an Excel worksheet. pandas.read_excel() reads worksheet values into a DataFrame, a labeled table with rows and columns. I’ll show how to read one sheet or collect several, and how to match the header and selected columns to…
-
Python Negative Index: How to Use It in Lists
To select an item by its position from the end of a Python list, use negative indexing. It counts from the list’s end, with -1 selecting the final item. This article shows how to replace a list item with a negative index. It also explains what happens when you try to get an item…
-
Atom IDE: Check Its Status for Python
Deciding whether to use Atom for Python means checking the editor’s support status and confirming that Python runs outside it. Atom is an open-source code editor, while a Python interpreter executes Python source code. This article shows how to check Atom’s GitHub repository and…
-
Custom Exceptions Python: Create and Handle Them
To handle an application-specific failure separately in Python, define a custom exception for it. A custom exception is a named error type that code can raise and callers can catch. This article shows how to define and raise a custom exception, then choose the message callers…
-
How to Open Files in Python
To read information saved in a file, your Python program first needs to open it. Python’s built-in open() function opens a path and returns a file object your program can use to read or write data. This article shows how to give open() the right path and read text inside a with…
-
Python String islower() Function
Working with letter case in Python can mean changing text or checking how it is already cased. The str.lower() method returns a lowercase copy of a string, while islower() reports whether its cased characters are lowercase. I’ll show how to call lower() and use its returned…
-
Isupper Python Method: Check Uppercase Strings
A string check can help a Python program choose what to do based on letter casing. Python’s str.isupper() returns True when a string has at least one cased character and every cased character is uppercase. You’ll see how to use the method in a conditional and when to use a…
-
Add Elements to Array Python
Adding values to a Python array starts with choosing how the new values should fit with the existing ones. A list can use append(value) to add one object at the end or extend(iterable) to add each item from an iterable. In this piece, I’ll show how to add one or several values…
-
Fractions Python: Create, Convert, and Calculate
Calculating with fractions in Python lets you work with values as ratios. The fractions module provides Fraction, which represents rational numbers as ratios of integers for arithmetic. I’ll show how to create fractions from decimal text and add them. TL;DR Python’s fractions…
-
Python isdigit: Check Unicode Digits in Strings
Checking whether a string contains digit characters is different from checking whether Python can parse it as an integer. Python’s str.isdigit() method tests whether every character in a non-empty string is a qualifying Unicode digit. I’ll show how to use isdigit() and when to…
-
np.outer(): Outer Product in NumPy
To calculate every pairwise product between two inputs, use NumPy’s np.outer function. It multiplies each value in one input by each value in the other and returns a two-dimensional array. This article explains how the input shapes determine the result and walks through an…
-
How to Convert Int to Float in Python
A calculation or function may need a floating-point value where you have an integer. Python’s float() function returns a float from an integer, such as 42.0 from 42. This article shows how to convert an integer with float() and check the result’s type. TL;DR Call float() with an…
-
Main function python: Write and Run It
To write and run a Python program, you can put its startup work in a function named main(). A check of __name__ == "__main__" calls that function when the file runs as the top-level program and skips that call when another file imports it. I’ll show how to use a guarded main()…
-
Lowest Python Values with min()
Comparing a few Python values or finding the smallest item in a list calls for a way to select the minimum. min() returns the lowest item from an iterable or from separate arguments. This article explains both ways to use min() and how to get the index of the selected item.…
-
4 How to Type Square Root in Python
Writing a square-root calculation in Python begins with deciding what kind of answer the calculation needs. Python can return a fractional square root or an integer floor root. This article explains how to choose among Python’s square-root methods and what to do with negative…
-
Python Wait: How to Pause Until a Set Time
A Python script may need to pause before it continues. Python’s wait functions pause a program for a chosen duration or until a condition changes. I’ll show how to add a fixed delay and use an asynchronous pause when other tasks need to keep running. TL;DR Call…
-
Not in Python: Boolean Operator and Membership Tests
When checking whether a Python value meets a condition, the expression depends on the question being asked. The not operator reverses a truth test, and not in checks whether a value is absent from a container. I’ll show how to choose the right negative test and explain what…
-
Python str.upper() Method: Syntax and Examples
Converting a Python string to uppercase gives it an uppercase form. Python’s str.upper() method returns a copy of a string with its cased characters converted to uppercase. I’ll show how to call str.upper() and what happens to the original string when you use the returned value.…
-
Python File Open: Read and Write Files
To read or change a file in Python, open it with a path and a mode. The open() function returns a file object your code can use to read or write data. This article shows how to read a text file line by line and choose a mode when writing. TL;DR Use open() with a […]
-
Critical Values in Python: Find a t Cutoff
To find a t critical value in Python, use the test’s significance level and degrees of freedom. A t critical value is a boundary from the t distribution that you compare with the test statistic. This article shows how to use SciPy to calculate the cutoff and select the…