Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active February 12, 2025 18:11
Show Gist options
  • Save sunmeat/8f56da7ad612fadaf9f79a2cb04bc71c to your computer and use it in GitHub Desktop.
Save sunmeat/8f56da7ad612fadaf9f79a2cb04bc71c to your computer and use it in GitHub Desktop.
built-in and mathematical python functions
# вбудовані функції: https://docs.python.org/uk/3.9/library/functions.html
text = "Hello"
print(len(text)) # 5 - повертає кількість елементів в об'єкті
print(type(text)) # <class 'str'> - повертає тип об'єкта
print(id(text)) # 2237317883936 - повертає унікальний ідентифікатор об'єкта
a = 5
b = a
print(id(a)) # 140710135260200
print(id(b)) # 140710135260200
numbers = [1, 5, 8, 3]
print(max(numbers)) # 8 - повертає максимальний елемент у колекції, також є min, sum, sorted
print(list(reversed(numbers))) # [3, 8, 5, 1]
fruits = ["apple", "banana", "cherry"]
for i, fruit in enumerate(fruits): # enumerate() — повертає кожен елемент з індексом
print(i, fruit)
value = -100
print(str(value)) # int(), float()
for i in range(5): # range()
print(i)
# name = input("Enter your name: ") # input()
################################################################################
# математичні функції: https://docs.python.org/uk/3/library/math.html
import math
base = 3
exponent = 4.5
print(pow(base, exponent)) # ступінь числа 140.29611541307906
number = 4.5678
print(round(number, 2)) # 4.57
print(math.sqrt(16)) # 4.0
print(math.ceil(4.3)) # 5
print(math.floor(4.7)) # 4
print(math.factorial(5)) # 120
print(math.radians(180)) # 3.141592653589793
print(math.degrees(math.pi)) # 180.0
print(math.sin(math.pi / 2)) # 1.0
print(math.cos(math.pi)) # -1.0
print(math.tan(math.pi / 4)) # 1.0
print(math.log(100, 10)) # 2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment