摘要:from itertools import permutationspaths = permutations([1, 2, 3]) # Generate all permutations of the list [1, 2, 3]for path in pat
执行基本算
术:
sum = 7 + 3 # Additiondifference = 7 - 3 # Subtractionproduct = 7 * 3 # Multiplicationquotient = 7 / 3 # Divisionremainder = 7 % 3 # Modulus (Remainder)power = 7 ** 3 # Exponentiation与复数一起工作:
z = complex(2, 3) # Create a complex number 2 + 3jreal_part = z.real # Retrieve the real partimaginary_part = z.imag # Retrieve the imaginary partconjugate = z.conjugate # Get the conjugate常用数学函数:
import mathroot = math.sqrt(16) # Square rootlogarithm = math.log(100, 10) # Logarithm base 10 of 100sine = math.sin(math.pi / 2) # Sine of 90 degrees (in radians)简单方法生成给定集合的排列:
from itertools import permutationspaths = permutations([1, 2, 3]) # Generate all permutations of the list [1, 2, 3]for path in paths: print(path)简单生成组合的方法:
from itertools import combinationscombos = combinations([1, 2, 3, 4], 2) # Generate all 2-element combinationsfor combo in combos: print(combo)获取随机数:
import randomnum = random.randint(1, 100) # Generate a random integer between 1 and 100当你需要处理分数时:
from fractions import Fractionf = Fraction(3, 4) # Create a fraction 3/4print(f + 1) # Add a fraction and an integer获取平均值、中位数和标准差:
import statisticsdata = [1, 2, 3, 4, 5]mean = statistics.mean(data) # Averagemedian = statistics.median(data) # Medianstdev = statistics.stdev(data) # Standard Deviation与三角学一起工作:
import mathangle_rad = math.radians(60) # Convert 60 degrees to radianscosine = math.cos(angle_rad) # Cosine of the angleimport mathinfinity = math.inf # Representing infinitynot_a_number = math.nan # Representing a non-number (NaN)来源:自由坦荡的湖泊AI
免责声明:本站系转载,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请在30日内与本站联系,我们将在第一时间删除内容!