A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3schools.com/python/ref_math_perm.asp below:

Website Navigation


Python math.perm() Method

Python math.perm() Method

❮ Math Methods

Example

Find the number of ways to choose k things from n items:

# Import math Library

import math

# Initialize the number of items to choose from

n = 7

# Initialize the number of items to choose

k = 5

# Print the number of ways to choose k items from n items

print (math.perm(n, k))

The result will be:

2520

Run Example » Definition and Usage

The math.perm() method returns the number of ways to choose k items from n items with order and without repetition.

Note: The k parameter is optional. If we do not provide one, this method will return n! (for example, math.perm(7) will return 5040).

Syntax Parameter Values Parameter Description n Required. Positive integers of items to choose from k Optional. Positive integers of items to choose

Note: If k is greater than n, it returns 0.

Note: If n or k are negative, a ValueError occurs. If n or k  are not integers, a TypeError occurs.

Technical Details Return Value: An int value, representing the number of ways to choose k items from n items with order and without repetition Python Version: 3.8

❮ Math Methods

Track your progress - it's free!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4