### 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.

2.6K views
##### How to comment out a block of Python code in Vim

I was wondering if there was any key mapping in Vim to allow me to indent certain lines of code (whether those

1.1K views
##### Why does Python&apos;s hash of infinity have the digits of π?

The hash of infinity in Python has digits matching pi: >>> inf = float('inf') >>>

431 views
##### Safest way to convert float to integer in python?

Python's math module contain handy functions like floor & ceil. These functions take a floating point

1.1K views
##### Calculating arithmetic mean (one type of average) in Python

Is there a built-in or standard library method in Python to calculate the arithmetic mean (one type of average

746 views
##### Convert a number range to another range, maintaining ratio

I'm trying to convert one range of numbers to another, maintaining ratio. Maths is not my strong point.

1.1K views
##### Fastest way to list all primes below N

This is the best algorithm I could come up. def get_primes(n): numbers = set(range(n, 1, -1)) primes

1.5K views
##### What is the standard way to add N seconds to datetime.time in Python?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so t

2.8K views
##### What is the difference between &apos;/&apos; and &apos;//&apos; when used for division?

Is there a benefit to using one over the other? In Python 2, they both seem to return the same results: >&

715 views
##### How can I check for NaN values?

float('nan') results in Nan (not a number). But how do I check for it? Should be very easy, but I ca

1.8K views
##### How to state in requirements.txt a direct github source

I've installed a library using the command pip install git+git://github.com/mozilla/elasticutils.git whi

261 views
##### How do I connect to a MySQL Database in Python?

How do I connect to a MySQL database using a python program?

441 views
##### Installing specific package versions with pip

I'm trying to install version 1.2.2 of the MySQL_python adaptor, using a fresh virtualenv created with th

3.1K views
##### open() in Python does not create a file if it doesn&apos;t exist

What is the best way to open a file as read/write if it exists, or if it does not, then create it and open it

1.7K views
##### Call Python function from MATLAB

I need to call a Python function from MATLAB. how can I do this?

2.5K views
##### reading v 7.3 mat file in python

I am trying to read a matlab file with the following code import scipy.io mat = scipy.io.loadmat('test.m

556 views
##### Why does numpy std() give a different result to matlab std()?

I try to convert matlab code to numpy and figured out that numpy has a different result with the std function.

676 views
##### What is the equivalent of MATLAB&apos;s repmat in NumPy

I would like to execute the equivalent of the following MATLAB code using NumPy: repmat([1; 1], [1 1 1]). How

2K views
##### What is the Python equivalent of Matlab&apos;s tic and toc functions?

What is the Python equivalent of Matlab's tic and toc functions?