File tree Expand file tree Collapse file tree 2 files changed +122
-0
lines changed
Expand file tree Collapse file tree 2 files changed +122
-0
lines changed Original file line number Diff line number Diff line change 1+ # Object Identity: is
2+ # Operation: and or not
3+
4+
5+ # General explanation
6+ # if True:
7+ # print('Conditional was True')
8+
9+ # 1 with var
10+ # language = 'Python'
11+ # if language == 'Python':
12+ # print('Conditional was True')
13+
14+ # Comparisons:
15+ # Equal: ==
16+ # Not Equal: !=
17+ # Greater Than: >
18+ # Less Than: <
19+ # Greater or Equal: >=
20+ # Less or Equal: <=
21+ # Object Identity: is # if the value have same id, same object in memory
22+
23+ ## 2 else statement
24+
25+ # language = 'Python'
26+ #
27+ # if language == 'Python':
28+ # print('Conditional was True')
29+ # else:
30+ # print('No match')
31+
32+ ## 3 elif
33+ language = 'Python'
34+
35+ if language == 'Python' :
36+ print ('language is python' )
37+ elif language == 'Java' :
38+ print ('language is java' )
39+ else :
40+ print ('No match' )
41+
42+ ## 4 and , or , not operation
43+
44+ # user = 'Admin'
45+ # logged_in = True
46+
47+ # if user == 'Admin' and logged_in:
48+ # print('Admin page')
49+ # else:
50+ # print('Bad Creds')
51+
52+ # not examle
53+ # if not logged_in:
54+ # print('Please Log in')
55+ # else:
56+ # print('Welcome')
57+
58+ ## 5 is operation
59+ # object id explanation
60+ # a = [1,2,3]
61+ # b = [1,2,3]
62+ #
63+ # print(a == b)
64+ # print (a is b)
65+ #
66+ # print(id(a))
67+ # print(id(b))
68+
69+ ## True and False values
70+ # False Values:
71+ # False
72+ # None
73+ # Zero of any numeric type
74+ # Any empty sequence. For example, '', (), [].
75+ # Any empty mapping. For example, {}.
76+
77+ # condition = False
78+ #
79+ # if condition:
80+ # print('Evaluated to True')
81+ # else:
82+ # print('Evaluated to False')
Original file line number Diff line number Diff line change 1+ # lambda expretion or lambda function
2+ # anonymous funtion - function that don't have name bounce to it
3+
4+ # regular function
5+ # def p(num):
6+ # return num ** 2
7+ # print(p(4))
8+ # print(type(p))
9+
10+ # lambda function general syntax :
11+ # y = lambda x: x ** 2
12+ # print(y(4))
13+ # print(y)
14+
15+ ## Why is usefull, for example :
16+ # def h(n):
17+ # return lambda x: (x + n) ** 2
18+ #
19+ # c = h(3)
20+ # b = h(0)
21+ # print(c)
22+ # print(b)
23+ #
24+ # print (b(2))
25+ # print(c(2))
26+
27+ ##
28+ # Another example build quadratic functions
29+
30+ # def build_quadratic_runction(a, b, c):
31+ # """Returns the function f(x)=ax^2 + bx + c"""
32+ # return lambda x: a*x**2 + b*x + c
33+ #
34+ # f = build_quadratic_runction(2, 3, -5)
35+ #
36+ # print(f(0))
37+ # print(f(1))
38+ # print(f(2))
39+ #
40+ # print(build_quadratic_runction(3, 0, 1)(2)) # 3x^2+1 evaluated for x=2
You can’t perform that action at this time.
0 commit comments