Repository navigation
Expand file tree
/
Copy pathComplete_Notes.txt
More file actions
executable file
·5464 lines (4041 loc) · 124 KB
/
Copy pathComplete_Notes.txt
File metadata and controls
executable file
·5464 lines (4041 loc) · 124 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
CODING CONVENTION
KEYWORDS
IDENTIFIERS
VARIABLES
DATA TYPES
TYPE CASTING
NUMBER CONVERSION
OPERATORS
STRING HANDLING
FLOW OF CONTROL
DATA STRUTURES - MANAGAEMENT SYSTEM
FUNCTIONAL PROGRAMMING
MODULE PROGRAMMING
MINOR PROJECT
OBJECT ORIENTED PROGRAMMING
EXCEPTION HANDLING
FILE HANDLING
DATA BASE CONNECTIVITY
MULTI-PROCESSING
GRAPHICAL USER INTERFACE
MAJOR PROJECT
CODE CONVENTION.
-----------------
THE FORMAT IN WHICH YOU SHOULD WRITE YOUR CODE.
variable -- variable_name
constant variable -- VARIABLE_NAME
module -- modulename
package -- packagename
function -- functionname()
classes -- ClassName
method -- methodName()
comments
---------
the code written inside some python module which is never going to get executed.
# single line comment
print("HELLO WORLD") # this statement will show hello world onto the screen
"""
this is also a comment
but it has mulitple lines
"""
'''
THIS IS ALSO A COMMENT
HAVING MORE THAN ONE LINE
'''
INDENTATION
------------
if a python object has a body then that body will be detemined using the indentation.
block:
print('HELLO WORLD')
print('HELLO WORLD') # these 3 statements belongs to block
print('HELLO WORLD')
print('HELLO WORLD')
print('HELLO WORLD')
KEYWORDS
-----------
these are predefined words which you can use only you will never be able to alter them.
these are total 35 in count.
code to list all the keywords
>>> from keyword import kwlist
>>> kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
>>> len(kwlist)
35
True - Yes
False - No
None - Nothing
IDENTIFIERS
------------
these are just names for the python objects which can be used to reference them.
-rules to define identifiers
1- it can never be a keyword
True = 10 # invalid
true = 10 # valid
2- it can never start with a number
1num = 10 # invalid
num1 = 10 # valid
3- it can not contain any special symbol or hidden symbol
num 1 = 10 # invalid because space.
num^y = 10 # invalid ^
4- only a single special symbol is allowed _ underscore it plays a very major role in python.
num_1 = 10 # valid
_num_1 = 10 # valid secure
__num_1 = 10 # valid highly secure
5- identifiers are case sensitive
num = 10
Num = 20
NUM = 30
# all are valid and diff. from each other.
recommendation.
6- keep identifiers as small as much you can but make sure it won't lost the understandablity.
number_1 = 10 # valid but not recommended
num_1 = 10 # valid and recommended
__1__ = 10 # valid
_1234 = 10 # valid
_ 10 = 20 # invalid
_ = 50 # valid
abc123& = 48 # invalid
__^__ = 78 # invalid
12_ = 78 # invalid
DISK OPERATING SYSTEM
---------------------
basic commands of dos.
-----------------------
-dir - directories
list all the files and folders available at current or given location.
E:\>dir
you will get your result here.
E:\>dir D:\folder
you will get your result here.
-tree
shows the structure of folder and file.
E:\>tree
shows the structure only for folder at current working directory
E:\>tree location
shows the structure for mentioned location only for folders
E:\>tree /f
shows the structure of files and folder at current working directory | current location
E:\>tree /f location
shows the structure of files and folder at given location
-drive name:enter
this command is used to switch the drive
E:\>f:
F:\>
-color change
this command will show you all the posible color available to be used as foreground and background
-color foreground-hexa background-hexa
F:\>color fc
F:\>color f1
F:\>color 0f
-help
shows the complete detailed list of all the available commands for the dos.
-cls
clears the screen
E:\>cls
DIRECTORY RELATED COMMANDS
--------------------------
md | mkdir - make directory
creates the directory at given location.
F:\>md krishna.py
F:\>md E:\harekrishna
F:\>md x y z
F:\>md "x y z"
rd | rmdir - remove directory
deletes the given directories - must be empty
F:\>rd krishna.py
F:\>md x\krishna
F:\>rd x
The directory is not empty.
F:\>rd /s x
x, Are you sure (Y/N)? y
-ren - rename
changes the name of any file or folder
old new
F:\>ren krishna krishna1234
-cd | chdir - change directory
it is used to open a folder.
F:\>cd krishna1234
F:\krishna1234>
F:\>cd project\demo\demoapp\migrations
F:\project\demo\demoapp\migrations>
-cd.. - close directory
shuts the single folder
F:\krishna1234>cd..
F:\>
F:\project\demo\demoapp\migrations>cd..
F:\project\demo\demoapp>cd\
F:\>
files commands of dos
-------------------------
-copy con
this command is used to create the file of any type.
F:\>copy con mypythonfile.py
# this will be the code written inside that file
# no dos command will work over here.
md
cd
cd..
cd\
# to save this file ctrl + z
^Z
1 file(s) copied.
F:\>
-type
this command is used to open a file.
F:\>type mypythonfile.py
# this will be the code written inside that file
# no dos command will work over here.
md
cd
cd..
cd\
# to save this file ctrl + z
-del
this command is used to delete a file.
F:\>del mypythonfile.py
-copy source destination
this command is used to copy a single file some other location
E:\pendrive>copy F:\output.mp4 .
. ==> indicates the current working directory
-xcopy source destination
copies more than file at a time.
E:\pendrive\newfile>xcopy F:\mattut .
F:\mattut\customizing matplotlib.ipynb
F:\mattut\piechart.png
F:\mattut\Plotting covid 19 spread.ipynb
F:\mattut\subplots_demo.ipynb
4 File(s) copied
-exit
this command will shut the dos
---------------------------------------------------------------------------
VARIABLES
-------------
variables is a booked place in computer memory to hold some value.
1-REFERENCE VARIABLES
these variables are created when they are required.
a place will be booked inside the computer memory and the python object(variable) will point to that location.
i-local
these variables are created inside some block and has scope only within that block.
they can never be accessed from outside of their creation block.
ii-global
these variables are directly created inside the program outside of any block and can be accessed from everywhere.
-garbage
a nameless object in computer memory.
-garbage collector
a functionality to remove all the garbage from memory for flowfull execution of python program.
2-PRIMITIVE VARIABLES - PYTHON DOES NOT HAVE THESE VARIABLES.
these variables are prely-created by the language compiler or interpretor and this is the reason you can find the size occupied by them.
since in python things are created whenever they are required so you can not find the size going to be occupied by the variable before its creation.
-UNITS OF DATA MEASUREMENT.
8 bits - Byte
1024 - Byte - 1 KB
1024 - KB - 1 MB
1024 - MB - 1 GB
1024 - GB - TB
a = 10 # global variable
#creating a block
def block():
a = 100 # local variable
print(a)
#executing the block
block()
def block1():
print(a)
block1()
print(a)
output
---------
E:\python 4 pm>python demo.py
100
10
10
---------------------------
a = 10 # global variable
#creating a block
def block():
a = 100 # local variable
print(a)
#executing the block
block()
def block1():
global a # you are telling python that you don't wanna make any new variable
a = 7800 # another local variable
print(a)
block1()
print(a)
output
----------
E:\python 4 pm>python demo.py
100
7800
7800
------------------------------
NONLOCAL
a = 100
#created a block
def block():
a = 1000
# created a inner block
def innerblock():
nonlocal a
a = 10000
print(a)
print(a)
# executed the inner block
innerblock()
print(a)
print(a)
#executing a block
block()
---------------------------------------------------
E:\python 4 pm>python demo.py
100
1000
10000
10000
-------------------------------------------
global keyword
this keyword is used to make changes into a global variable from inside of a block
nonlocal
this keyword is used to make changes into a local variable from inside of some inner block.
-----------------------------------------------------------------------------------------------------
INPUT AND OUTPUT | I/O
----------------------------
the major need of any application is to communicate with the user
io helps the application to communicate with the user by allowing user to given value to it and by providing the values to user the application also communicates with the user.
print(value1,value2,...,sep=" ",end="\n")
takes infinite values from you and print them onto the console seperating them with the given seperator and at the end of print statement end value will be placed as full stop.
print(4,5,8,"krishna",'hare krishna',sep="|",end=".")
E:\python 4 pm>python demo.py
4 5 8 krishna hare krishna
E:\python 4 pm>python demo.py
4.5.8.krishna.hare krishna
E:\python 4 pm>python demo.py
4|5|8|krishna|hare krishna.
E:\python 4 pm>
ESCAPE SEQUENCES
-----------------
these are just special chars which represents the special symbol.
\n - linebreak
\t - tabspace
\\ - print backslash
\' - print single quote
\" - print double quote
input("single optional msg")
prints the optional msg onto the console then allow the user to enter some value then takes that value from user and return that back into the code where ever that input function was written.
all the value had by the input function will be only in form of string | words.
a = input("ENTER A NUMBER PLEASE : ")
print(a)
DATA TYPES
--------------
the types which are used categorize the data that you are going to deal with.
data type helps you to find the set of operations allowed on data.
you are never allowed to set the type of data.
type(object)
it tells you to type of given object.
>>> a = 1
>>> type(a)
<class 'int'>
>>>
int
in python every non decimal number will be considered as only integer.
>>> a = 1
>>> type(a)
<class 'int'>
>>>
>>> a = 12345645641654165415641654165416516516516519819681968516158614654658196851498516
>>> type(a)
<class 'int'>
>>>
float
every number which contains at least one decimal place then that number will be considered as float only.
>>> a = 1.1
>>> type(a)
<class 'float'>
>>>
>>> a = 1.5216548564968541961496841968541984968489641964198498419849849846984
>>> type(a)
<class 'float'>
>>>
complex
this data type is only availale in python.
with the help of complex data type you can store a number with imaginary part as well.
very rearly used data type.
>>> a = 10+50j # you can use upper case j also.
>>> type(a)
<class 'complex'>
>>>
bool
can contain only True or False.
>>> a = True
>>> type(a)
<class 'bool'>
>>> a = False
>>> type(a)
<class 'bool'>
>>>
str
string is nothing but the word of programming.
anything surrounded with '' or "" or """ """ or ''' ''' will be considered as string only.
>>> a = "krishna"
>>> type(a)
<class 'str'>
>>> a = 'krishna'
>>> type(a)
<class 'str'>
>>> a = """
... this is also
... a string
... """
>>> type(a)
<class 'str'>
>>> a = '''
... this is also
... a string
... '''
>>> type(a)
<class 'str'>
>>> type("HELLO WORLD") # anonymous string
<class 'str'>
>>>
-various number system
in python you will never be able to start a number with zero but if you are required to store only 0 then that is allowed.
0 at begining of any number indicates some other number system is going to be used.
1-binary number system - base 2
this is the number system which is getting used by all the machines.
allowed digits - 0 and 1
it represents binary system - 0B | 0b
>>> a = 0b010101010101010
>>> a
10922
>>>
2-octal number system - base 8
allowed digits 0 to 7
0o | 0O
>>> a = 0o123456
>>> a
42798
3-hexadecimal number system - base 16
allowed digits 0 to 9 and a to f
0x | 0X
>>> a = 0x123458679abcdef
>>> a
81985662092037615
4- integer number system base - 10
allowed digits - 0 to 9
no representation is required
>>> a = 123
>>> a
123
anonymous object
an object which does not have any identifier assigned to it.
x = '12345' - str
x = 4.45 - float
x = "4.85" - str
x = "True" - str
x = False - bool
x = 0b10101010 - int
x = "0xabcd" - str
q- write a program which will accept the name of student and marks of 5 subjects
OUTPUT
--------
NAME : USER WILL ENTER
---------------MARKS----------------
HINDI : USER WILL ENTER
ENGLISH : "
MATH : "
SCIENCE : "
HISTORY : "
------------REPORT CARD-------------
************NAME*********************
HINDI : VALUE
MATH : VALUE
SCIENCE : VALUE
ENGLISH : VALUE
HISTORY : VALUE
TYPE CASTING
-------------
type casting is the process of converting one data type some other data type
python is dynamically typed language so in python we can never decide for a variable the fixed type of value the python is going to determine the type with the help of value assigned to a variable.
x - this will contain only integer number X
# simple program to have two number from and and print their sum
x = input("ENTER A NUMBER : ") # '75'
y = input("ENTER A NUMBER : ") # '45'
print(x+y)
in this above code python will consider the values returned by inpu function as string only even if they are number.
python has a set of functions available to perform the type casting.
1-int(object)
this function type casts all the object to integer except non numeric string "krishna132" X
where "123456789" this string is totally valid.
complex number is also not allowed.
>>> x = input('ENTER A NUMBER : ')
ENTER A NUMBER : 75
>>> y = input("ENTER A NUMBER : ")
ENTER A NUMBER : 45
>>> type(x)
<class 'str'>
>>> type(y)
<class 'str'>
>>> x = int(x)
>>> y = int(y)
>>> type(x)
<class 'int'>
>>> type(y)
<class 'int'>
>>> print(x+y)
120
>>>
or
# simple program to have two number from and and print their sum
x = int(input("ENTER A NUMBER : ")) # '75'
y = int(input("ENTER A NUMBER : ")) # '45'
print(x+y)
NOT ALLOWED TO BE TYPE CASTED.
>>> x = "krishna" # NON NUMERIC STRING
>>> int(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'krishna'
>>> x = 45+85j # COMPLEX IS ALSO NOT ALLOWED
>>> int(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to int
>>>
>>> int(45.854845648125465)
45
>>> int(True)
1
>>> int(False)
0
>>> int("45615")
45615
>>>
float(object)
any data type to float it can type cast but not non numerical string and complex numbers.
>>> float("12")
12.0
>>> float(True)
1.0
>>> float(False)
0.0
>>> float(int("0xabcd",base=16))
43981.0
>>>
complex(object)
any data type to complex but not non numeric string (except if string is in complex format)
>>> complex(1)
(1+0j)
>>> complex(True)
(1+0j)
>>> complex("4155")
(4155+0j)
>>> complex("415+45j")
(415+45j)
>>> complex("415+45x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: complex() arg is a malformed string
>>>
bool(object)
any object to boolean it can type cast.
0 and None - False
other - True
>>> bool()
False
>>> bool(0)
False
>>> bool("")
False
>>> bool(None)
False
>>> bool("krishna")
True
>>> bool(54646)
True
>>> bool(54.4549684)
True
>>>
str(object)
any object to string.
>>> str(45)
'45'
>>> str(45.45)
'45.45'
>>> str(45+85j)
'(45+85j)'
>>> str(True)
'True'
>>>
Q- HAVE A NUMBER FROM USER AND PRINT THE CONVERTION INTO ALL NUMBER SYSTEM OF GIVEN NUMBER
ENTER A NUMBER : 10
binary -
octal -
hexa -
------------------------------------------
# SIMPLE INTEREST CALC
p = float(input('ENTER AMOUNT OF LOAN : '))
r = float(input('RATE : '))
t = float(input('ENTER PERIOD IN YEARS : '))
# P*R*T/100
#150000.0*'9'*'5'
print('SIMPLE INTEREST IS : ',p*r*t/100)
----------------------------------------------------------
p = float(input('ENTER AMOUNT OF LOAN : '))
r = float(input('RATE : '))
t = float(input('ENTER PERIOD IN YEARS : '))
si = p*r*t/100
mi= (si+p)/(t*12)
print(f"LOAN AMOUNT IS : {p:,}")
print(f'INTEREST IS : {si:,}')
print(f'MONTHLY INSTALLMENT IS : {mi:,} FOR {t*12} MONTHS')
----------------------------------------------------------------------
NUMBER SYSTEM
--------------
python has wide range of number systems but natively python uses integer number system
integer number system - base 10
allowed digits are 0-9
python defaultly follows this number system.
binary number system - base 2
allowed digits are 0 and 1
0b0101001110010
0B1100010010101
>>> 0b101010101011111
21855 # python will convert every number to integer automatically.
>>> 0b1010101010121111
File "<stdin>", line 1
0b1010101010121111
^
SyntaxError: invalid digit '2' in binary literal
>>>
octal number system - base 8
allowed digits 0-7
0o12345607
0O123456
>>> 0o12345670
2739128 # python will convert every number to integer automatically.
>>> 0o123456708
File "<stdin>", line 1
0o123456708
^
SyntaxError: invalid digit '8' in octal literal
>>>
hexadecimal number system - base 16
allowed digits 0-9 | a-f | A-F
0xabcdef
0Xabcdef
>>> 0x1234567890abcdef
1311768467294899695
>>> 0x1234567890abcdefg
File "<stdin>", line 1
0x1234567890abcdefg
^
SyntaxError: invalid syntax
>>>
LITERALS
these are just values which we use in our code.
-NUMBER LITERAL
1-integer literal
123456789
2-binary literal
0b101010101
3-octal literal
0o1234567
4-hexadecimal literal
0xabcdef123456789
-FLOAT LITERAL
12.45496
-COMPLEX LITERAL
45+85j
-BOOLEAN LITERALS
True
False
-STRING LITERALS
'KRISHNA'
"False"
"""True"""
'''True'''
note:in python if you wish to store any other number system then integer number system then you can only store it as string literal
>>> a = 0b1010101010101010
>>> a
43690
>>> a = '0b1010101010101010'
>>> a
'0b1010101010101010'
>>>
NUMBER CONVERSION.
--------------------
CONVERTING OTHER NUMBER SYSTEM TO INT. | NUMBER CONVERSION.
int(number literal,base=10)
BINARY TO INTEGER
>>> x = "123456789"
>>> int(x)
123456789
>>> x = "0b101010"
>>> int(x,base=2)
42
>>> int(0b101010)
42
>>> 0b101010
42
OCTAL TO INTEGER
>>> int("0o01234567",base=8)
342391
>>>
HEXADECIMAL TO INTEGER
>>> int("0xabcdef123456789",base = 16)
773738363261118345
bin(number)
converts any number system to binary number system.
INTEGER TO BINARY
>>> bin(42)
'0b101010'
>>>
OCTAL TO BINARY -> OCTAL - INT - BINARY
>>> bin(int("0o123456",base=8))
'0b1010011100101110'
>>>
HEXA TO BINARY -> HEXA - INT - BINARY
>>> bin(int("0xabcd",base=16))
'0b1010101111001101'
>>>
oct(number)
INT TO OCTAL
>>> oct(45)
'0o55'
>>>
BIN TO OCT -> BIN - INT - OCT
>>> oct(int("0b1010",base=2))
'0o12'
>>>
HEXA TO OCT -> HEXA - INT - OCT
>>> oct(int("0xabcde",base=16))
'0o2536336'
hex(number)
INT TO HEX
>>> hex(42)
'0x2a'
OCT TO HEX -> OCT - INT - HEXA
>>> hex(int("0o12345",base=8))
'0x14e5'
--------------------------------------------------------------------------------
OPERATORS
------------
operators tell python that which action to perform with the given operands
a = 10