Python

Python is a dynamic, strongly typed, object-oriented, multipurpose programming language, designed to be quick (to learn, to use, and to understand), and to enforce a clean and uniform syntax. Two similar but incompatible versions of Python are in use (Python 2.7 or 3.x). For version-specific Python questions, please also use the [python-2.7] or [python-3.x] tags. When using a Python variant (Jython, Pypy, Iron-python, etc.) - please also tag the variant.

47 votes
11 answers
450 views
Dump a NumPy array into a csv file

Is there a way to dump a NumPy array into a CSV file? I have a 2D NumPy array and need to dump it in human-rea

avatar
Joseph
0 1 0 9
asked 07 September, 2021
57 votes
21 answers
1.9K views
How to print the full NumPy array, without truncation?

When I print a numpy array, I get a truncated representation, but I want the full array. Is there any way to

avatar
Cortez
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
2.3K views
How to get the last element of a list?

In Python, how do you get the last element of a list?

avatar
Margo
0 1 0 9
asked 07 September, 2021
55 votes
11 answers
1.4K views
Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3?

It is my understanding that the range() function, which is actually an object type in Python 3, generates its

avatar
Elicia
0 1 0 9
asked 07 September, 2021
57 votes
29 answers
1.5K views
How do I parse a string to a float or int?

In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or par

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
54 votes
24 answers
2.6K views
Converting string into datetime

I've got a huge list of date-times like this as strings: Jun 1 2005 1:33PM Aug 28 1999 12:00AM I&apos

avatar
Fabian
0 1 0 9
asked 07 September, 2021
52 votes
15 answers
3.1K views
How to access environment variable values

I set an environment variable that I want to access in my Python application. How do I get its value?

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
495 views
How to print colored text to the terminal?

How can I output colored text to the terminal in Python?

avatar
Hallie
0 1 0 9
asked 07 September, 2021
60 votes
22 answers
2.3K views
How do you change the size of figures drawn with Matplotlib?

How do you change the size of figure drawn with Matplotlib?

avatar
Keith
0 1 0 9
asked 07 September, 2021
52 votes
30 answers
1.2K views
How do you split a list into evenly sized chunks?

I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There a

avatar
Lawanda
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
992 views
How can I install pip on Windows?

pip is a replacement for easy_install. But should I install pip using easy_install on Windows? Is there a bett

avatar
Jeff
0 1 0 9
asked 07 September, 2021
55 votes
13 answers
558 views
How to delete a file or folder in Python?

How do I delete a file or folder in Python?

avatar
Boyd
0 1 0 9
asked 07 September, 2021
49 votes
10 answers
938 views
Manually raising (throwing) an exception in Python

How can I raise an exception in Python so that it can later be caught via an except block?

avatar
Royal
0 1 0 9
asked 07 September, 2021
53 votes
11 answers
1.3K views
How do I select rows from a DataFrame based on column values?

How can I select rows from a DataFrame based on values in some column in Pandas? In SQL, I would use: SELECT *

avatar
Freida
0 1 0 9
asked 07 September, 2021
58 votes
16 answers
503 views
55 votes
23 answers
867 views
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

In the following method definitions, what does the * and ** do for param2? def foo(param1, *param2): def bar(

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
65 votes
7 answers
1.7K views
Understanding Python super() with __init__() methods

I'm trying to understand the use of super(). From the looks of it, both child classes can be created,

avatar
Nidia
0 1 0 9
asked 07 September, 2021
59 votes
12 answers
1.4K views
What is __init__.py for?

What is __init__.py for in a Python source directory?

avatar
Renaldo
0 1 0 9
asked 07 September, 2021
52 votes
22 answers
1.7K views
List changes unexpectedly after assignment. Why is this and how can I prevent it?

While using new_list = my_list, any modifications to new_list changes my_list every time. Why is this, and how

avatar
Elicia
0 1 0 9
asked 07 September, 2021
67 votes
17 answers
821 views
How to make function decorators and chain them together?

How can I make two decorators in Python that would do the following? @makebold @makeitalic def say(): retu

avatar
Shanita
0 1 0 9
asked 07 September, 2021