Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common implementation methods of Python

Shulou Source: shulou.com Published: 2022-06-02 13:01:18 10月03日 Update

This article mainly explains "what are the common implementation methods of Python", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the common Python implementation methods?"

1. Bubble sorting

Lis = [56 [lis]-1]: if lis [j] > lis [jung1]: lis [j], lis [juni1] = lis [juni1], lis [j] return lis if _ name__ ='_ _ main__': sortport () print (lis)

2. Calculate the n power of x

Def power (x, n): s = 1 while n > 0: n = n-1 s = s * x return s

Call method:

Print (power (2p4))

3. Calculate afia + breadb + cystec +...

Def calc (* numbers): sum=0 for n in numbers: sum=sum+n*n return sum print (calc)

4. Calculate factorial n!

# method 1: def fac (): num = int (input ("Please enter a number:") factorial = 1 # check whether the number is negative, 0 or positive if num

Tags: Input numbers characters methods letters strings leap years factorials lowercase files paths maximum uppercase negative output columns directories instances years integers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB Microsoft Huawei vpn