forked from JMSwag/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_example.py
More file actions
73 lines (50 loc) · 1.72 KB
/
Copy pathfunction_example.py
File metadata and controls
73 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
__author__ = 'ipetrash'
def my_sum(*args):
s = 0
for arg in args:
s += int(arg)
return s
def my_print(**kwargs):
for name, value in kwargs.items():
print("%s=%s(%s)" % (name, value, type(value)))
def sql_insert(table, **kwargs):
# Example: INSERT INTO users (login, pass) values('TestUser', '123456')
columns = kwargs.keys()
values = ["'%s'" % x for x in kwargs.values()]
return "INSERT INTO %s (%s) VALUES (%s)" % (table, ', '.join(columns), ', '.join(values))
def say_hello(word="World", spl="!"):
print("Hello, " + word + spl)
def my_min(a, b):
return min(a, b)
def my_max(a, b):
return max(a, b)
def binary_operation(a, b, func):
return func(a, b)
# http://pythonworld.ru/tipy-dannyx-v-python/vse-o-funkciyax-i-ix-argumentax.html
if __name__ == '__main__':
print(my_sum(1, 2, 3, 4))
my_print(a=2, b=3, c="Foo")
print(sql_insert("Users", login="TestUser", pas=123))
print(sql_insert("Users", login="Vasya", pas=123, sex="male"))
say_hello()
say_hello("Py")
say_hello(spl="?")
say_hello(spl="?!", word="man")
print()
a = 2
b = 4
print("1: %d" % binary_operation(a, b, my_min))
print("2: %d" % binary_operation(a, b, my_max))
print("3: %d" % binary_operation(a, b, min))
print("4: %d" % binary_operation(a, b, max))
print("5: %d" % binary_operation(a, b, lambda a, b: a * b))
print("6: %d" % binary_operation(a, b, lambda a, b: a ** b))
print()
lambda_sum = lambda a, b: a + b
print(lambda_sum(1, 1))
print(lambda_sum(1.1, 1.9))
print(lambda_sum('a', 'bc'))
print(lambda_sum([1, 2], [3, 4]))
print()
print((lambda a, b: a ** b)(2, 3))
print((lambda a, b: a / b)(4, 2))