RUVIDEO
Поделитесь видео 🙏

(B17) Python part12 Lambda function, Math function - pow, sqrt, ceil,floor, pi смотреть онлайн

📁 Лайфстайл 👁️ 16 📅 02.12.2023

20220523 104703
Python Lambda
A lambda function is a small anonymous function.

A lambda function can take any number of arguments, but can only have one expression.

Syntax
lambda arguments : expression
The expression is executed and the result is returned:

Example
Add 10 to argument a, and return the result:

x = lambda a : a + 10
print(x(5))

--------
x = lambda a : a +10
print(x(5))
15
x = lambda a, b: a +b
print(x(34,12))
46
print(x(23,66))
89
y = lambda a,b,c: (a+b) -c
print(y(12,45,77))
-20
z = lambda a,b: (a+b)**2
print(z(4,5))
81
--------------------------------------
Why Use Lambda Functions?
The power of lambda is better shown when you use them as an anonymous function inside another function.

Say you have a function definition that takes one argument, and that argument will be multiplied with an unknown number:

def myfunc(n):
return lambda a : a * n
Use that function definition to make a function that always doubles the number you send in:

Example
def myfunc(n):
return lambda a : a * n

mydoubler = myfunc(2)

print(mydoubler(11))

--------------
def myfun(n):
print("n=",n)
return lambda a: a * n

m2 = myfun(2)
m3 = myfun(3)

print(m2(33))
print(m3(44))

-----------------
def myfun(n,m):
print("n=",n,"m=",m)
return lambda a,b: a * n + b * m

m2 = myfun(2,3)
m3 = myfun(3,2)

print(m2(55,77))
------------------------------------
Python Math
Python has a set of built-in math functions, including an extensive math
module, that allows you to perform mathematical tasks on numbers.

Built-in Math Functions
The min() and max() functions can be used to find the lowest or highest value in an iterable:

Example
x = min(5, 10, 25)
y = max(5, 10, 25)

print(x)
print(y)

x = [21,33,62,16,83,39]

print("Minimum value of x",min(x))
print("Maximum value of x",max(x))
---------------------
The abs() function returns the absolute (positive) value of the specified number:

Example
x = abs(-7.25)

print(x)
-----------
a = 100
b = 234
print(abs(a-b))
--------------------------
The pow(x, y) function returns the value of x to the power of y (xy).

Example
Return the value of 4 to the power of 3 (same as 4 * 4 * 4):

x = pow(4, 3)

print(x)
----------------------------
pow(3,2)
9
pow(4,3)
64
pow(9,2)
81
pow(3,3)
27
pow(17,3)
4913
-------------------------------
The Math Module
Python has also a built-in module called math, which extends the list of mathematical functions.

To use it, you must import the math module:

import math
When you have imported the math module, you can start using methods and constants of the module.

The math.sqrt() method for example, returns the square root of a number:

Example
import math

x = math.sqrt(64)

print(x)
---------------
import math

print(math.sqrt(121))
--------------------------
import math

#Use the Pythagorean theorem to calculate the hypotenuse from right triangle sides.
#Take a square root of sum of squares: c = √(a² + b²)
a=int(input('a='))
b=int(input('b='))

c = a **2 + b **2
x = math.sqrt(c)

print("The hypotenuse:",x)
-----------------------------------------------------------------
The math.ceil() method rounds a number upwards to its nearest integer,
and the math.floor() method rounds a number downwards to its nearest integer, and returns the result:

Example
import math

x = math.ceil(1.4)
y = math.floor(1.4)

print(x) # returns 2
print(y) # returns 1
-----------------------------------------
import math
print('Find avg of 3 numbers, and round of the avg')
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))

avg = (a+b+c)/3

x = math.ceil(avg)
y = math.floor(avg)

print('avg:',avg,'ceil',x,'floor',y)
-------------------------------------------
The math.pi constant, returns the value of PI (3.14...):

Example
import math

x = math.pi

print(x)
--------------------
import math
print('Find area of circle')
r = int(input("enter radius r :"))
x = math.pi

print("area of a circle", x * r**2)
-----------------------------------------------

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «(B17) Python part12 Lambda function, Math function - pow, sqrt, ceil,floor, pi» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.