-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuiltin-FUNCTIONS.py
More file actions
1337 lines (984 loc) · 27.6 KB
/
Builtin-FUNCTIONS.py
File metadata and controls
1337 lines (984 loc) · 27.6 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
########## BUILT-IN FUNCTIONS ##########
## Functions need "arguments"
# ex: sin(x)= ? --> x is an argument
## there cannot be more than one instruction in a line !!!
## The instructions in the code are executed in the same order in which they have been placed in the source file
# no subsequent instruction is executed until the previous one is completed
## What happens when Python encounters an invocation
# 1- Python checks if the name specified is legal: it browses its internal data in order to find an existing function of the name
# if this search fails, Python aborts the code
# 2- Python checks if the function's requirements for the number of arguments allows you to invoke the function in this way
# 3- Python leaves your code for a moment and jumps into the function you want to invoke; of course, it takes your argument(s) too and passes it/them to the function
# 4- the function executes its code, causes the desired effect (if any), evaluates the desired result(s) (if any) and finishes its task
# finally, Python returns to your code (to the place just after the invocation) and resumes its execution
### abs()
# Returns the absolute value of a number
x = abs(-7.25)
print(x)
7.25
### all()
# Returns True if all items in an iterable object are true
mylist = [True, True, True]
x = all(mylist)
print(x)
True
mylist = [1, "string", [1,2,3], (1,2,3), {1:"one",2:"two"}]
x = all(mylist)
print(x)
True
### any()
# Returns True if any item in an iterable object is true
mylist = [False, True, False]
x = any(mylist)
True
### ascii()
# Returns a readable version of an object
# Replaces none-ascii characters with escape character + ascii characters
x = ascii("My name is Ståle")
print(x)
# My name is St\e5le
### bin()
# Returns the binary version of a number; the result will always have the prefix 0b
x = bin(36)
print(x)
0b100100
### bool()
# Returns the boolean value of the specified object and will always return True, unless the object is empty, like [], (), {}, False, 0, or None
# When bool() is provided an empty list, an empty string or the value 0 it returns False
# The expression will evaluate to True when bool () is given any other value, including negative numbers
x = bool(10)
print(x)
True
x = bool("jeanjaques)")
print(x)
True
x = bool(None)
print(x)
False
x = []
y = ""
z = -1
print(bool(x),bool(y),bool(z))
# False False True
### bytearray()
# Returns an array of bytes
x = bytearray(4)
print(x)
bytearray(b'\x00\x00\x00\x00') # à quoi ça sert ??
### bytes()
# Returns a bytes object
x = bytes(6)
print(x)
b'\x00\x00\x00\x00\x00\x00'
### callable()
# In general, a callable is something that can be called
# This built-in method in Python checks and returns True if the object passed appears to be callable, otherwise False
def x():
a = 5
print(callable(x))
True
print(callable(5))
# False
print(callable("Hello"))
# False
print(callable(len))
# True
### chr()
# Returns a character from the specified Unicode code.
# Invoking it with an invalid argument (e.g., a negative or invalid code point) causes ValueError or TypeError exceptions
x = chr(97)
print (x)
"a"
x = chr(32)
print (x)
"a"
x = chr(32) # SPACE
print (x)
#
### classmethod()
# Converts a method into a class method
class Person:
age = 25
def printAge(cls):
print('The age is:', cls.age)
Person.printAge = classmethod(Person.printAge) # create printAge class method
Person.printAge()
"The age is: 25"
### compile()
# Returns the specified source as an object, ready to be executed
# compile() takes 3*arguments :
# 1st = source code ex:()'print(55)\nprint(88)')
# 2nd = file name
# 3rd = execution mode ex:('exec')
x = compile('print(55)\nprint(88)', 'test', 'exec')
exec(x)
55
88
### complex()
# Returns a complex number, complex(real,imaginary)
x = complex(3, 5)
print(x)
# (3+5j)
# In Python, suffix "j" is used to represent the virtual part
x = complex(3)
print(x)
# (3+0j)
x = complex('3+5j')
print(x)
# (3+5j)
### delattr()
# Deletes the specified attribute (property or method) from the specified object
class Person:
name = "John"
age = 36
country = "Norway"
delattr(Person, 'age') # The Person object will no longer contain an "age" property
### dict()
# Returns a dictionary (Array)
x = dict(name = "John", age = 36, country = "Norway")
print(x)
{'name': 'John', 'age': 36, 'country': 'Norway'}
# .__dict__
# __dict__ is a special attribut spécial of any object in Python
#It is a dictionnary which contains all the object attributes from constructor, methods, direct, along with thei values
# Example
class MaClass:
class_var = 1
def __init__(self):
self.x = 10
self.y = 20
def print(self):
return self.x + self.y
def print2(self):
self.z = self.x + self.y
return self.z
obj = MaClass()
print(obj.__dict__)
# {'x': 10, 'y': 20} ==> from __init__
print(obj.print())
# 30
print(obj.__dict__)
# {'x': 10, 'y': 20}
print(obj.print2())
30
print(obj.__dict__)
{'x': 10, 'y': 20, 'z': 30}
print(MaClass.__dict__) # ==> class variables de class + functions + static attributes (here x, y, z)
# {'__module__': '__main__', '__firstlineno__': 1, 'class_var': 1,
# '__init__': <function MaClass.__init__ at 0x00000170C5F03E20>, 'print': <function MaClass.print at 0x00000170C5F11940>,
# 'print2': <function MaClass.print2 at 0x00000170C5F10C20>,
# '__static_attributes__': ('x', 'y', 'z'), '__dict__': <attribute '__dict__' of 'MaClass' objects>,
# '__weakref__': <attribute '__weakref__' of 'MaClass' objects>, '__doc__': None}
### dir()
# != de .__dict__ !!
# returns a list of the specified object's properties and methods
# PARAMETER can be a variable, a module, (), None
# RETURN can be a list of:
# the module's attribute
# names of class attributes
# names of object attributes
# names of the base class attributes
# object/class
class MaClass:
class_var = 1
def __init__(self):
self.x = 10
self.y = 20
def print(self):
return self.x + self.y
def print2(self):
self.z = self.x + self.y
return self.z
obj = MaClass()
print(obj.__dict__)
# {'x': 10, 'y': 20} ==> from __init__
print(dir(obj))
# ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__',
# '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__',
# '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
# '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__weakref__',
# 'class_var', 'print', 'print2', 'x', 'y']
print(MaClass.__dict__) # ==> class variables + functions + static attributes (ici x, y, z)
# {'__module__': '__main__', '__firstlineno__': 1, 'class_var': 1,
# '__init__': <function MaClass.__init__ at 0x00000170C5F03E20>, 'print': <function MaClass.print at 0x00000170C5F11940>,
# 'print2': <function MaClass.print2 at 0x00000170C5F10C20>,
# '__static_attributes__': ('x', 'y', 'z'), '__dict__': <attribute '__dict__' of 'MaClass' objects>,
# '__weakref__': <attribute '__weakref__' of 'MaClass' objects>, '__doc__': None}
print(dir(MaClass))
# ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__',
# '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__',
# '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
# '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__weakref__',
# 'class_var', 'print', 'print2']
# module
import math
for name in dir(math):
print(name, end=" ")
# __doc__ __loader__ __name__ __package__ __spec__ acos acosh asin asinh atan atan2 atanh cbrt ceil comb
# copysign cos cosh degrees dist e erf erfc exp exp2 expm1 fabs factorial floor fma fmod frexp fsum gamma
# gcd hypot inf isclose isfinite isinf isnan isqrt lcm ldexp lgamma log log10 log1p log2 modf nan nextafter
# perm pi pow prod radians remainder sin sinh sqrt sumprod tan tanh tau trunc ulp
# current local
print(dir())
# ['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
# None
print(dir(None))
# ['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__',
# '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
# '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
### divmod()
# Returns the quotient and the remainder when argument1 is divided by argument2
x = divmod(5, 2)
print(x)
(2, 1)
### enumerate()
# Takes a collection (e.g. a tuple) and returns it as an enumerate object
x = ('apple', 'banana', 'cherry')
y = enumerate(x)
print(y)
# enumerate object at 0x14dd63cdc300 # ?? To see what is into this obect, we must convert it into a list or iterate it thru a loop
print(list(y))
[(0, 'apple'), (1, 'banana'), (2, 'cherry')]
animaux = ['girafe', 'tigre', 'singe', 'souris']
for i, animal in enumerate(animaux):
print(i, animal)
#0 girafe
#1 tigre
#2 singe
#3 souris
### eval()
# Evaluates and executes an expression
x = 'print(55)'
eval(x)
# 55
result = eval("2 + 3")
print(result)
# 5
# Evaluating variables
x = 10
print(eval("x + 5"))
# 15
x, y = eval(input('Enter two numbers: ')) # 3, 4
print(x)
print(y)
# 3
# 4
### exec()
# Executes the specified code (or object)
x = 'name = "John"\nprint(name)'
exec(x)
# 'John'
### filter()
# Use a filter function to exclude items in an iterable object
numbers = (1, 2, 5, 9, 15)
def filter_numbers(num):
nums = (1, 5, 17)
if num in nums:
return True
else:
return False
filtered_numbers = filter(filter_numbers, numbers)
for n in filtered_numbers:
print(n)
# 1
# 5
ages = [5, 12, 17, 18, 24, 32]
def myFunc(x):
if x < 18:
return False
else:
return True
adults = filter(myFunc, ages) # not printable, it is just a filter
print (adults)
# <filter object at 0x0000023D9F925C00>
for x in adults:
print(x)
# 18
# 24
# 32
### float()
# Returns a floating point number
x = float(3)
print(x)
# 3.0
print (float("1, 3"))
# ValueError: could not convert string to float: '1,3'
# float() waits a point . de séparation not a comma ,
print (float("1.3"))
# or
z = float("1,3".replace(",", "."))
print(z)
# we can replace it with an input.replace
### format()
# Formats a specified value
x = format(0.5, '%')
print(x)
# 50.000000%
### frozenset()
# Returns a frozenset object
mylist = ['apple', 'banana', 'cherry']
x = frozenset(mylist)
print(x)
# frozenset({'apple', 'cherry', 'banana'})
### getattr()
# Returns the value of the specified attribute (property or method)
class Person:
name = "John"
age = 36
country = "Norway"
x = getattr(Person, 'age')
print(x)
# 36
### globals()
# Returns the current global symbol table as a dictionary A QUOI CA SERT ???
x = globals()
print(x)
# {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x02A8C2D0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'demo_ref_globals.py', '__cached__': None, 'x'_ {...}}
### hasattr()
# Returns True if the specified object has the specified attribute (property/method)
class Person:
name = "John"
age = 36
country = "Norway"
x = hasattr(Person, 'age')
print(x)
# True
### hash()
# Returns the hash value of a specified object
# hash for integer unchanged= integer itself ==> ?
x = "test"
y = 35689
z = 35689.23
print (hash(x), hash(y), hash(z))
# -9195877821982143216 35689 530343892126567273
### help()
# Executes the built-in help system
print (help(list))
'''
Help on class list in module builtins:
class list(object)
| list(iterable=(), /)
|
| Built-in mutable sequence.
|
| If no argument is given, the constructor creates a new empty list.
| The argument must be an iterable if specified.
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __gt__(self, value, /)
| Return self>value.
|
| __iadd__(self, value, /)
| Implement self+=value.
|
| __imul__(self, value, /)
| Implement self*=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(self, /)
| Return a reverse iterator over the list.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(self, /)
| Return the size of the list in memory, in bytes.
|
| append(self, object, /)
| Append object to the end of the list.
|
| clear(self, /)
| Remove all items from list.
|
| copy(self, /)
| Return a shallow copy of the list.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| extend(self, iterable, /)
| Extend list by appending elements from the iterable.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first of value.
|
| Raises ValueError if the value is not present.
|
| insert(self, index, object, /)
| Insert object before index.
|
| pop(self, index=-1, /)
| Remove and return item at index (default last).
|
| Raises IndexError if list is empty or index is out of range.
|
| remove(self, value, /)
| Remove first occurrence of value.
|
| Raises ValueError if the value is not present.
|
| reverse(self, /)
| Reverse *IN PLACE*.
|
| sort(self, /, *, key=None, reverse=False)
| Sort the list in ascending order and return None.
|
| The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
| order of two equal elements is maintained).
|
| If a key function is given, apply it once to each list item and sort them,
| ascending or descending, according to their function values.
|
| The reverse flag can be set to sort in descending order.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...) from builtins.type
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
'''
### hex()
# Converts a number into a hexadecimal value
x = hex(255)
print(x)
# 0xff
### id()
# Returns the id of an object = the memory address of the object
# will be different every time you run the program
x = ('apple', 'banana', 'cherry')
y = id(x)
print(y)
# 47642599593984
x = ('apple', 'banana', 'cherry')
y = id(x)
print(y)
# 22520260536256
class A:
def __init__(self, x=0):
self.x = x
obj1 = A(2)
obj2 = A(2)
print(id(obj1) == id(obj2))
# False # objects are different
print(id(obj1))
# 2384063197744
print(id(obj2))
# 1253138468048
obj1 = A(2)
obj2 = obj1 # here obj2 is a strict copy of obj1
print(id(obj1) == id(obj2))
# True
print(id(obj1))
# 1773527200304
print(id(obj2))
# 1773527200304
dict1 = {1:"a",2:"b"}
dict2 = dict1
print(id(dict1) == id(dict2))
# True
str1 = 'Hello'
str2 = 'Hello'
print(id(str1) == id(str2))
# True ==> varaibles sharing the same string value have the same id()
print(id(str1))
# 1905559360672
print(id(str2))
# 1905559360672
### input()
# Allowing user input, the result of the input() function is a string
fnam = input("May I have your first name, please? ")
# James
lnam = input("May I have your last name, please? ")
#Bond
print("Thank you.")
print("\nYour name is " + fnam + " " + lnam + ".")
# Thank you.
#
# Your name is James Bond.
### int()
# Returns an integer number
x = int(3.5)
y = int(3.7)
print(x)
print(y)
# 3
# 3
b = "20.2"
print (int(b))
# ..
# print (int(b))
# ValueError: invalid literal for int() with base 10: '20.2'
data = ['Peter', 'Paul', 'Mary']
print(data[int(-1 / 2)]) # = data[0]
# Peter
### isinstance()
# Returns True if a specified object is an instance of a specified object
x = isinstance(5, int)
y = isinstance("test", float)
print(x)
print(y)
# True
# False
### issubclass()
# Returns True if a specified class is a subclass of a specified object
# Check if the class myObj is a subclass of myAge
class myAge:
age = 36
class myObj(myAge):
name = "John"
age = myAge
x = issubclass(myObj, myAge)
print(x)
# True
### iter()
# Returns an iterator object
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
# apple
# banana
# cherry
# if more (next(x)) than existing iterations ==> error, we should use prefer "for" loop
x = iter(["apple", "banana", "cherry"])
for item in iter(["apple", "banana", "cherry"]):
print(next(x))
# apple
# banana
# cherry
### len()
# Returns the length of an object
mylist = ["apple", "orange", "cherry"]
x = len(mylist)
print(x)
# 3
i_am = 'I\'m' # = I'm
print(len(i_am))
# 3
multiline = '''Line #1
Line #2'''
print(len(multiline))
# 15 as \n = 1 character
data = ()
print(data.__len__())
# 0
print(data.__len__() == len(data))
# True
### list()
# Returns a list
x = list(('apple', 'banana', 'cherry'))
print(x)
# ['apple', banana', 'cherry']
### locals()
# Returns an updated dictionary of the current local symbol table
x = locals()
print(x)
# {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0327C2D0>,
# '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'demo_ref_globals.py', '__cached__': None, 'x'_ {...}}
### map()
# Returns the specified iterator with the specified function applied to each item
def myfunc(n):
return len(n)
x = map(myfunc, ('apple', 'banana', 'cherry'))
print(x)
print(list(x)) #convert the map into a list, for readability:
# <map object at 0x056D44F0>
# [5, 6, 6]
letters = ["beach", "car"]
funified = list(map(lambda word: f"{word} is fun!", letters)) # Cette partie est une fonction anonyme (ou fonction lambda)
# Elle prend un argument word et retourne une nouvelle chaîne de caractères
print(funified)
# ['beach is fun!', 'car is fun!']
### max()
# Returns the largest item in an iterable
x = max(5, 10)
y = max([5, 10, 552, 10489 , 10000003])
z = max({"horse" : 14, "dog" : 20, "cat" : 18})
print(x)
print(y)
print(z)
# 10
# 10000003
# "horse" # takes item alphabetic order, not its value
### memoryview()
# Returns a memory view objectcherry
x = memoryview(b"Hello")
print(x)
# <memory at 0x03348FA0>
### min()
# Returns the smallest item in an iterable
x = min(5, 10)
y = min([5, 10, 552, 10489 , 10000003])
z = min({"horse" : 14, "dog" : 20, "cat" : 18})
print(x)
print(y)
print(z)
# 5
# 5
# "cat" # takes item alphabetic order, not its value
### next()
# Returns the next item in an iterable
mylist = iter(["apple", "banana", "cherry"])
x = next(mylist)
print(x)
# "apple"
x = next(mylist)
print(x)
# "banana"
x = next(mylist)
print(x)
# "cherry"
### object()
# Returns a new object
x = object()
print(dir(x))
# ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
# '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__',
# '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
### oct()
# Converts a number into an octal
x = oct(12)
print(x)
# Oo14
### open()
# Opens a file and returns a file object
f = open("demofile.txt", "r")
print(f.read())
# 30/08/2022 ACHAT CB ASF-LANCON 30.08.22
# CARTE NUMERO 816 - 3,00 €
#
# 30/08/2022 ACHAT CB ASF-SENAS 30.08.22
# CARTE NUMERO 816 - 3,00 €
#
# 29/08/2022 ACHAT CB ESCOTA CAPITOU 29.08.22
# CARTE NUMERO 816 - 15,80 €
#
# 29/08/2022 ACHAT CB ESCOTA LA BARQ 29.08.22
# CARTE NUMERO 816 - 15,80 €
#
# 26/08/2022 ACHAT CB ASF, 4 PAIEMEN 25.08.22
# CARTE NUMERO 816 - 14,80 €
#
# 22/08/2022 ACHAT CB ASF-LANCON 19.08.22
# CARTE NUMERO 816 - 3,00 €
#
# 22/08/2022 ACHAT CB ASF-SENAS 19.08.22
# CARTE NUMERO 816 - 3,00 €
#
# 16/08/2022 ACHAT CB ESCOTA, 2 PAIE 16.08.22
# CARTE NUMERO 816 - 27,20 €
#
# 16/08/2022 ACHAT CB ASF-AVIGNON-N 16.08.22
# CARTE NUMERO 816 - 7,20 €
#
# 08/08/2022 ACHAT CB ESCOTA CAPITOU 08.08.22
# CARTE NUMERO 816 - 15,80 €
#
# 08/08/2022 ACHAT CB ESCOTA LA BARQ 08.08.22
# CARTE NUMERO 816 - 15,80 €
#
# 05/08/2022 ACHAT CB ESCOTA MEYRARG 02.08.22
# CARTE NUMERO 816 - 13,60 €
### ord()
# Convert an integer representing the Unicode of the specified character
x = ord("h")
print(x)
# 104
### pow(x, y)
# Returns the value of x to the power of y
print(pow(2, 4))
# 16