About 563,000 results
Open links in new tab
  1. Function for factorial in Python - Stack Overflow

    Jan 6, 2022 · The easiest way is to use math.factorial (available in Python 2.6 and above): import math math.factorial(1000) If you want/have to write it yourself, you can use an iterative …

  2. How to write help/description text for Python functions?

    I have to write many functions and was wondering how I can incorporate a help or description text such that it appears in the object inspector of Spyder when I call the function. In MATLAB, this …

  3. python - Writing string to a file on a new line every time - Stack …

    Oct 23, 2017 · Unless write to binary files, use print. Below example good for formatting csv files: def write_row(file_, *columns): print(*columns, sep='\t', end='\n', file=file_)

  4. What is the proper way to comment functions in Python?

    Dec 14, 2019 · Read about using docstrings in your Python code. As per the Python docstring conventions: The docstring for a function or method should summarize its behavior and …

  5. Code for Greatest Common Divisor in Python - Stack Overflow

    Jun 24, 2012 · #This program will find the hcf of a given list of numbers. A = [65, 20, 100, 85, 125] #creates and initializes the list of numbers def greatest_common_divisor(_A): iterator = 1 …

  6. Python writing function output to a file - Stack Overflow

    Feb 6, 2015 · A better solution is to open the file outside the function and pass it in as an argument (perhaps using a with statement around the function calls so it gets closed …

  7. Simplest async/await example possible in Python - Stack Overflow

    Jun 8, 2018 · In case 2, we added async to the normal function. However the event loop will run it without interruption. Why? Because we didn't say where the loop is allowed to interrupt your …

  8. python - Solving Quadratic Equation - Stack Overflow

    Mar 14, 2013 · Python: only print the result within a tolerance for a quadratic equation 0 How to find the centre and radius of a circle that passes through a specific point and is tangential to line

  9. how to find a prime number function in python - Stack Overflow

    using your code, and focusing on code structure: def is_prime(x): # function contents must be indented if x == 0: return False elif x == 1: return False # your base cases need to check X, not …

  10. How to implement a good __hash__ function in python

    It's dangerous to write. def __eq__(self, other): return other and self.a == other.a and self.b == other.b because if your rhs (i.e., other) object evaluates to boolean False, it will never compare …

Refresh