From b51004890cd186acd523d7fa9cf90f100d540cc5 Mon Sep 17 00:00:00 2001 From: Amol Kahat Date: Sat, 28 Mar 2020 22:05:36 +0530 Subject: [PATCH 1/7] Added more descriptive explaination of decorators. Signed-off-by: Amol Kahat --- main_book.tex | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/main_book.tex b/main_book.tex index 1dc47bc..ec62e1e 100644 --- a/main_book.tex +++ b/main_book.tex @@ -852,7 +852,7 @@ \section{Decorators} Yes.. it will show you address of that function. It is telling you that function is present at some location on memory. If you will get address of that function then you can play around it. \paragraph{} - Remember we didn't called the function but we just print it's memory location. If that is the case then I can pass this function as an argument to another function. +Remember we did not called the function yet, we just print it's memory location. If that is the case then we can pass this function as an argument to another function (like call by reference in C). \begin{lstlisting} >>> def wrapper(func): @@ -866,9 +866,10 @@ \section{Decorators} After func >>> \end{lstlisting} -In above example, I wrote another function name as wrapper and passed one argument to it, and called it with two parameters. When I called wrapper function that time I passed add function reference to it. +In above example, I wrote another function name as 'wrapper' and passed one argument 'add' in it, and inside the wrapper function I called function 'func' with two parameters. +After hitting enter, we could see that function add print addition 30 in between 'Before func' and 'After func'. \paragraph{} -So basically this happened, I passed add to wrapper and when wrapper get called it printed "Before func" then it will call add function which takes two arguments and return the result, After that it will print "After func". So this passed add function is get called within the wrapper function. +So basically this happened, I passed 'add' to 'wrapper' and when wrapper get called it printed "Before func" then it will call 'add' function which takes two arguments and return and print the result, After that it will print "After func". So this passed add function is get called within the 'wrapper' function. \paragraph{} Python allows us to decorate the functions using decorator, so we can write the code like this \begin{lstlisting} @@ -878,7 +879,7 @@ \section{Decorators} ... print("After func") ... >>> @wrapper -... def hell_world(): +... def hello_world(): ... print("Hello World") ... Before func @@ -888,6 +889,23 @@ \section{Decorators} \end{lstlisting} When you decorate any function, by default python interpreter call wrapper function add pass "hello\textunderscore world" function reference in to it. +\paragraph{} +Basically we can write above decorator function in simple form +\begin{lstlisting} +>>> def wrapper(func): +... print("Before func") +... func() +... print("After func") +... +>>> @wrapper +... def hello_world(): +... print("Hello World") +... +Before func +Hello World +After func +\end{lstlisting} +Okay.. now I expect you got some understanding of the decorators. You might have notice that it get called automatically by the interpreter. \section{Exception Handling} In Python there are multiple built in exceptions are present. Exceptions are designed to handle the error in running program. Consider if you are converting the strings to the integer, which is against the Python programming language rule. To handle this situation exceptions are used. If exceptions are not used then program will crash. @@ -983,7 +1001,7 @@ \subsection{Objects} \end{lstlisting} \subsection{Constructors} \subsubsection{Default Constructors} -Constructors are the methods which are called when the objects are created. In Python you can defined the constructors, which will get called when object is get created. +Constructors are the methods which are called when the objects are created. In Python you can defined the constructors, which get called when object got created. \begin{lstlisting} class math_op(): @@ -1052,8 +1070,28 @@ \subsection{Magic Methods} \item $\textunderscore\textunderscore len \textunderscore\textunderscore()$ To Count the length of the object. (Uses with $len()$) \item $\textunderscore\textunderscore dir \textunderscore\textunderscore()$ Return the methods associated with the class. (Uses with $dir()$) \end{itemize} +\section{Inheritance} \section{File Operations} \section{Modules} +Implementing modules in Python is very easy. Modules are nothing but the file with the class. If you want to use those classes then you can directly import those classes in your code. +Let's create on file wich has 2 classes. Class A has get_a and set_a methods and Class B has get_b and set_b methods. + +\begin{lstlisting} + class A: + a = 10 + def get_a(self): + return self.a + + def set_a(self, a): + self.a = a + + class B: + b = 20 + def get_b(self): + return self.b + +\end{lstlisting} + \subsection{sys module} sys module is used to check the which type of system it is, This module gives you the details about the system, consider you don't know which OS you have Mac OS, Linux OS and Windows, you can find out it using sys module. \begin{lstlisting} @@ -1081,11 +1119,10 @@ \subsection{os module} ... # os.makedirs(): To create nested directory recursively. ... # os.rmdir() : To remove single directory. ... # os.removedirs(): To remove nested directory recursively. - \end{lstlisting} \subsection{re module} \subsection{sqlite module} \section{Python Built In methods} \part{Testing with Python} \part{Django} -\end{document} \ No newline at end of file +\end{document} From 0adc42358674e54086b63a19ae1b27366ccea7e0 Mon Sep 17 00:00:00 2001 From: Amol Kahat Date: Sat, 28 Mar 2020 23:23:24 +0530 Subject: [PATCH 2/7] Added Builtin methods section and description. Signed-off-by: Amol Kahat --- main_book.tex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main_book.tex b/main_book.tex index ec62e1e..9e946c1 100644 --- a/main_book.tex +++ b/main_book.tex @@ -1123,6 +1123,28 @@ \subsection{os module} \subsection{re module} \subsection{sqlite module} \section{Python Built In methods} +Python as language it has some of it's features. It imports some of the functions and variables by default, So you don't need to call modules to execute this function. Well this is perfect match for 'Beautiful is better than Ugly' from Zen of Python. +\paragraph{} +Python has some of the 'builtins' methods and classes which are imported by default. Open interpreter and type dir\(\textunderscore \textunderscore biltins \textunderscore \textunderscore\). +\begin{lstlisting} +>>> dir(__builtins__) +['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'] +\end{lstlisting} +You could see the list of the 'builtin' Exception and methods. If you want to execute those methods and Execption you can directly call them in the interpreter. +Like we used 'print' before and list, dict, range etc. +\paragraph{} +All those are coming form the builtin module. And by default this module is assigned to the \textunderscore \textunderscore builtin \textunderscore \textunderscore. +Let's check that out. +\begin{lstlisting} +>>> import builtins +>>> id(builtins) +139815372774672 +>>> id(__builtins__) +139815372774672 +\end{lstlisting} +Yes.. id of the both are same. You can try to import from 'builtins' and run it will return the same result. +\paragraph{} +All the list items are starting with Capital letters are the Exceptions. And rest are the methods. \part{Testing with Python} \part{Django} \end{document} From 253ff4ab1ce1b6066996a6a777eb8349b71b4d1b Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Tue, 31 Mar 2020 00:32:18 +0530 Subject: [PATCH 3/7] fix build --- main_book.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_book.tex b/main_book.tex index 9e946c1..3c6850c 100644 --- a/main_book.tex +++ b/main_book.tex @@ -1074,7 +1074,7 @@ \section{Inheritance} \section{File Operations} \section{Modules} Implementing modules in Python is very easy. Modules are nothing but the file with the class. If you want to use those classes then you can directly import those classes in your code. -Let's create on file wich has 2 classes. Class A has get_a and set_a methods and Class B has get_b and set_b methods. +Let's create on file wich has 2 classes. Class A has get\_a and set\_a methods and Class B has get\_b and set\_b methods. \begin{lstlisting} class A: From 3180f7c3c16f65fc4c3f4c15231c6b63f3e1fa0b Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Tue, 31 Mar 2020 00:51:16 +0530 Subject: [PATCH 4/7] github action --- .github/workflows/main.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b61c444 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +name: Python Book + +on: [push, pull_request] + +jobs: + tex: + name: Checks and Build + runs-on: ubuntu-latest + steps: + - name: Checkout to master + uses: actions/checkout@master + + - name: Check Indentation + run: make indent + + - name: Syntex Checks + run: make checks + + - name: build PDFLaTeX + run: make build + + - name: Analysis (git diff) + if: failure() + run: git diff + From d1d43dcdcf83864c172b7ac527b9db1fd8f29509 Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Tue, 31 Mar 2020 00:59:23 +0530 Subject: [PATCH 5/7] fix indentation --- main_book.tex | 194 +++++++++++++++++++++++++------------------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/main_book.tex b/main_book.tex index 3c6850c..d74f696 100644 --- a/main_book.tex +++ b/main_book.tex @@ -102,58 +102,58 @@ \subsection{Relational Operators} True >>> 10 != 10 False -\end{lstlisting} +\end{lstlisting} \subsection{Bitwise Operators} Bitwise operators are used to perform bit operations on the numbers. Those numbers are treated as string of bits written in twos complement binary. \begin{itemize} -\item 0 is written as "0" -\item 1 is written as "1" -\item 2 is written as "10" -\item 3 is "11" -\item . -\item . -\item 1029 is ``10000000101" == 2**10 + 2**2 + 2**0 == 1024 + 4 + 1 + \item 0 is written as "0" + \item 1 is written as "1" + \item 2 is written as "10" + \item 3 is "11" + \item . + \item . + \item 1029 is ``10000000101" == 2**10 + 2**2 + 2**0 == 1024 + 4 + 1 \end{itemize} \subsubsection{Operators} \begin{itemize} -\item $x \ll y$ : $x$ operator is shifted to left by $y$ bits and it return result of $x$ with shifted $y$ bits. It is same as $x * 2 ** y$ -\begin{lstlisting} + \item $x \ll y$ : $x$ operator is shifted to left by $y$ bits and it return result of $x$ with shifted $y$ bits. It is same as $x * 2 ** y$ + \begin{lstlisting} >>> 3<<2 12 >>> 3*2**2 12 \end{lstlisting} -\item $x \gg y$ : $x$ operator is shifted to right by $y$ bits and it return result of $x$ with shifted $y$ bits. It is same as $x // 2 ** y$. -\begin{lstlisting} + \item $x \gg y$ : $x$ operator is shifted to right by $y$ bits and it return result of $x$ with shifted $y$ bits. It is same as $x // 2 ** y$. + \begin{lstlisting} >>> 8>>2 2 >>> 8//2**2 2 \end{lstlisting} -\item $x \& y $: Bitwise AND, each bit of output is 1 if corresponding bit of $x$ AND $y$ is 1, otherwise it is 0 -\begin{lstlisting} + \item $x \& y $: Bitwise AND, each bit of output is 1 if corresponding bit of $x$ AND $y$ is 1, otherwise it is 0 + \begin{lstlisting} >>> 8 & 8 8 >>> 8 & 2 0 \end{lstlisting} -\item $x | y$ : Bitwise OR, each bit of output is 1 if corresponding bit of $x$ AND $y$ is 1, otherwise it is 0 -\begin{lstlisting} + \item $x | y$ : Bitwise OR, each bit of output is 1 if corresponding bit of $x$ AND $y$ is 1, otherwise it is 0 + \begin{lstlisting} >>> 2 | 2 2 >>> 2 | 4 6 >>> \end{lstlisting} -\item $\sim x $: Complement, It will gives complement of $x$, the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1. -\begin{lstlisting} + \item $\sim x $: Complement, It will gives complement of $x$, the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1. + \begin{lstlisting} >>> ~2 -3 \end{lstlisting} -\item $x \wedge y$ : Does a ``bitwise exclusive or". Each bit of the output is the same as the corresponding bit in $x$ if that bit in $y$ is 0, and it's the complement of the bit in $x$ if that bit in $y$ is 1. -\begin{lstlisting} + \item $x \wedge y$ : Does a ``bitwise exclusive or". Each bit of the output is the same as the corresponding bit in $x$ if that bit in $y$ is 0, and it's the complement of the bit in $x$ if that bit in $y$ is 1. + \begin{lstlisting} >>> 1^1 0 >>> 1^2 @@ -167,20 +167,20 @@ \subsection{Keywords} List of keywords present in the Python\\ \begin{center} -\begin{tabular}{llll} -class & False & None & True\\ -and & as & assert & break \\ -continue & def & del & elif \\ -else & expect & finally & for \\ -from & global & if & import \\ -in & is & lambda & not \\ -or & pass & raise & return \\ -try & while & with & yield -\end{tabular} + \begin{tabular}{llll} + class & False & None & True \\ + and & as & assert & break \\ + continue & def & del & elif \\ + else & expect & finally & for \\ + from & global & if & import \\ + in & is & lambda & not \\ + or & pass & raise & return \\ + try & while & with & yield + \end{tabular} \end{center} \section{Variables and assignment} -Python is dynamically typed language, it means it will decide what to do with your input at the run time. +Python is dynamically typed language, it means it will decide what to do with your input at the run time. Variable declaration and definition in python is something different. If you want to define integer in other languages, for that you follow this syntax \texttt{ = } @@ -215,7 +215,7 @@ \section{Conditional statements} \subsection{If statement} If statement is conditional statement. It is used to check the condition between two variables. -Any non zero value is considered as a True value. In python it's syntax is little bit different. +Any non zero value is considered as a True value. In python it's syntax is little bit different. True keyword is used to represent boolean value. In first statement condition is true so it will print the if block. In second statement $ 10 > 10 $ condition is false, it will not print ``True statement". \begin{lstlisting} @@ -230,7 +230,7 @@ \subsection{If statement} \end{lstlisting} \subsection{if..else statement} -Like I mentioned in the above statement if is the conditional statement, in if statement if the condition is true, then it will execute the if block or it will skip it. +Like I mentioned in the above statement if is the conditional statement, in if statement if the condition is true, then it will execute the if block or it will skip it. Here if condition is false then, else block got executed. \begin{lstlisting} @@ -245,7 +245,7 @@ \subsection{if..else statement} \subsection{if..elif statement} -In the python switch statement is not present. If you want to check any choice which is matches to the multiple statement then you need to use elif statement. +In the python switch statement is not present. If you want to check any choice which is matches to the multiple statement then you need to use elif statement. elif statement is check the condition, if the condition is true then it will execute the block or else block. @@ -273,8 +273,8 @@ \subsection{if..elif statement} \section{Loops} In Python there are two main loops: \begin{enumerate} -\item For loop -\item While loop + \item For loop + \item While loop \end{enumerate} \subsection{For loop} @@ -469,7 +469,7 @@ \subsection{String Slicing} 'H' >>> s[-1] 'o' -\end{lstlisting} +\end{lstlisting} Python will give you more easy syntax to access the string. In python you can access the strings with the following syntax. \begin{lstlisting} [start:stop:jump] @@ -514,22 +514,22 @@ \section{Lists} \end{lstlisting} \subsection{List methods} \begin{itemize} -\item append(): To append element to the list. -\item clear(): To clear the list. -\item copy(): To copy the list in to the another variable. \footnote{ If we can directly copy one variable using assignment operator then why we need `copy' method?\\ Basically in python when assignment (=) operator, that time new variable just simply point to the list location. -\\ -So if you change the list using old variable then new variable will reflect the change. But if you create new variable using copy(), then your new variable did not get affected.\\ - -} - -\item count(): Count the element occurrences in the list. -\item extend(): To extend the existing list with another list. You can pass any object (string, list, dict, set) it will extend it to the list. -\item index(): It will return index of the element. -\item insert(): To insert the element at specific location. This method accepts two parameters, 1st one is index and 2nd is value. -\item pop(): To pop the element from the list. By default it will remove the elements from the end of the list. If you want to remove the elements from any location then you can pass index at it. -\item remove(): To remove the element from the list. -\item reverse(): To reverse the list. -\item sort(): To sort the elements in the list. + \item append(): To append element to the list. + \item clear(): To clear the list. + \item copy(): To copy the list in to the another variable. \footnote{ If we can directly copy one variable using assignment operator then why we need `copy' method?\\ Basically in python when assignment (=) operator, that time new variable just simply point to the list location. + \\ + So if you change the list using old variable then new variable will reflect the change. But if you create new variable using copy(), then your new variable did not get affected.\\ + + } + + \item count(): Count the element occurrences in the list. + \item extend(): To extend the existing list with another list. You can pass any object (string, list, dict, set) it will extend it to the list. + \item index(): It will return index of the element. + \item insert(): To insert the element at specific location. This method accepts two parameters, 1st one is index and 2nd is value. + \item pop(): To pop the element from the list. By default it will remove the elements from the end of the list. If you want to remove the elements from any location then you can pass index at it. + \item remove(): To remove the element from the list. + \item reverse(): To reverse the list. + \item sort(): To sort the elements in the list. \end{itemize} \clearpage @@ -611,8 +611,8 @@ \section{Tuples} \subsubsection{Tuple methods} You can check the properties of the Tuples using \textbf{dir} method. You will find only two properties. \begin{itemize} -\item count(): It will give you the count of the elements in the tuple. -\item index(): It will give you the index of the element. + \item count(): It will give you the count of the elements in the tuple. + \item index(): It will give you the index of the element. \end{itemize} \subsubsection{Operations on Tuples} As we saw in the lists, you can add two Tuples. Ex: @@ -667,7 +667,7 @@ \subsubsection{Tuple Slicing} \section{Dictionaries} Dictionaries are based on the hash tables data structure in C. Dictionaries are defined using key and value. You can use curly braces ${}$ to define the dictionaries. -Dictionaries are based on key and values. For each value there is one key associated with it. +Dictionaries are based on key and values. For each value there is one key associated with it. \begin{lstlisting} >>> d = {} >>> d = {'country': 'India', @@ -687,7 +687,7 @@ \section{Dictionaries} 'Marathi', 'Gujarati'] \end{lstlisting} -Keys in the dictionary are anything those can be string, integer, floating point values or any module object. +Keys in the dictionary are anything those can be string, integer, floating point values or any module object. \begin{lstlisting} >>> import os >>> d = {} @@ -701,16 +701,16 @@ \section{Dictionaries} \subsection{Dictionary Methods} Dictionary have following methods: \begin{itemize} -\item clear() : To clear the dictionary. -\item copy() : To copy the dictionary to the another variable. -\item get() : Get is used for getting the value of the specific key in the dictionary or it will return \texttt{None}. -\item items() : This method will return the all the items in the dictionary inside the list. This list will consist the pair of the key and value tuple. -\item keys() : This method will return all the keys inside the dict. -\item pop() : This method will pop specified key and return the value. -\item popitem(): This method will pop any random key and value from they dictionary, it will return the tuple of key and value. -\item update(): This method will update the dictionary with new values or old keys with new values. -\item values() : This method will return the list of the all values. -\item fromkeys() : This method will return the new dictionary with keys from iterable and values equal to values. + \item clear() : To clear the dictionary. + \item copy() : To copy the dictionary to the another variable. + \item get() : Get is used for getting the value of the specific key in the dictionary or it will return \texttt{None}. + \item items() : This method will return the all the items in the dictionary inside the list. This list will consist the pair of the key and value tuple. + \item keys() : This method will return all the keys inside the dict. + \item pop() : This method will pop specified key and return the value. + \item popitem(): This method will pop any random key and value from they dictionary, it will return the tuple of key and value. + \item update(): This method will update the dictionary with new values or old keys with new values. + \item values() : This method will return the list of the all values. + \item fromkeys() : This method will return the new dictionary with keys from iterable and values equal to values. \end{itemize} \subsection{Iteration on Dictionary} You can iterate on the dictionary using the for loop. By default it will iterate on the keys. @@ -748,7 +748,7 @@ \subsection{Iteration on Dictionary} \section{Functions} Function is a block of statements which will perform single action. Function will provide modular code, which will be more easy to read. You can reuse this code to perform some action which will save your time. -In Python you can define the function using the \texttt{def} keyword. +In Python you can define the function using the \texttt{def} keyword. After the def keyword you define the name of the function and later in the parenthesis you provide the arguments, after the arguments line ends with the \texttt{$:$} which indicate that from the next line body of the function will be begin. \begin{lstlisting} >>> def add(): @@ -782,11 +782,11 @@ \section{Functions} None >>> \end{lstlisting} -In above example add function will return the value, which is addition of the two numbers. You can store that value in a variable for later use. +In above example add function will return the value, which is addition of the two numbers. You can store that value in a variable for later use. \paragraph{} Let's see other side, what if function do not return any value? In that case it will return \texttt{None} keyword. You can see the example in above code with function sub. Function will print the subtraction but it will not return anything. By default the value is \texttt{None}. \subsection{Functions with arguments} -In functions arguments can be passed, In function you can pass $n$ no of arguments. To pass the arguments in the function you do not need to specify the data type, which we specify in C, C++ or Java. As mentioned earlier, Python is dynamic language. +In functions arguments can be passed, In function you can pass $n$ no of arguments. To pass the arguments in the function you do not need to specify the data type, which we specify in C, C++ or Java. As mentioned earlier, Python is dynamic language. \begin{lstlisting} >>> def add(a, b): @@ -812,11 +812,11 @@ \subsection{Functions with arguments} If you are not passing expected arguments to the function then function will throw an error. \subsection{*args and **kwargs in Function} -*args and **kwargs are play major role in function arguments. Consider if you want to pass $n$ no of arguments in to the function, some languages have restrictions on that, you can pass the arguments which are defined in the function. But Python gives you more scope to pass the $n$ no of arguments to the function. +*args and **kwargs are play major role in function arguments. Consider if you want to pass $n$ no of arguments in to the function, some languages have restrictions on that, you can pass the arguments which are defined in the function. But Python gives you more scope to pass the $n$ no of arguments to the function. \begin{itemize} -\item **args used for the passing $n$ no of positional arguments tot the function. -\begin{lstlisting} + \item **args used for the passing $n$ no of positional arguments tot the function. + \begin{lstlisting} >>> def add(*args): ... return sum(args) ... @@ -825,9 +825,9 @@ \subsection{*args and **kwargs in Function} 210 >>> \end{lstlisting} -*args accept all the arguments in to the tuple. -\item **kwargs used for the passing $n$ no of key and value based arguments to the function. -\begin{lstlisting} + *args accept all the arguments in to the tuple. + \item **kwargs used for the passing $n$ no of key and value based arguments to the function. + \begin{lstlisting} >>> def details(**kwargs): ... print(kwargs) ... @@ -835,7 +835,7 @@ \subsection{*args and **kwargs in Function} >>> details(name='John',surname='Doe',age=10,height=5.5) {'name': 'John', 'surname': 'Doe', 'age': 10, 'height': 5.5} \end{lstlisting} -**kwargs accepts all the arguments in to the dictionary. + **kwargs accepts all the arguments in to the dictionary. \end{itemize} \section{Decorators} @@ -869,7 +869,7 @@ \section{Decorators} In above example, I wrote another function name as 'wrapper' and passed one argument 'add' in it, and inside the wrapper function I called function 'func' with two parameters. After hitting enter, we could see that function add print addition 30 in between 'Before func' and 'After func'. \paragraph{} -So basically this happened, I passed 'add' to 'wrapper' and when wrapper get called it printed "Before func" then it will call 'add' function which takes two arguments and return and print the result, After that it will print "After func". So this passed add function is get called within the 'wrapper' function. +So basically this happened, I passed 'add' to 'wrapper' and when wrapper get called it printed "Before func" then it will call 'add' function which takes two arguments and return and print the result, After that it will print "After func". So this passed add function is get called within the 'wrapper' function. \paragraph{} Python allows us to decorate the functions using decorator, so we can write the code like this \begin{lstlisting} @@ -960,7 +960,7 @@ \section{Exception Handling} print("Hello") \end{lstlisting} -In above program if you provide another value expect digits then you will get value error. If you provide the any digit except 1 then it will throw an key error. +In above program if you provide another value expect digits then you will get value error. If you provide the any digit except 1 then it will throw an key error. Exception is generic class, if you don't know which error will occur then you will write Exception class and print it. \begin{lstlisting} @@ -979,9 +979,9 @@ \section{Exception Handling} print("Hello") \end{lstlisting} \section{Class} -Class is nothing but the group of the methods and variables. Classes are the basic building block of Object Oriented programming. +Class is nothing but the group of the methods and variables. Classes are the basic building block of Object Oriented programming. \paragraph{} -In Python you can define the classes using $class$ keyword. Inside the class you can define the methods which are class methods. To define the methods are related to the class, first argument passed is $self$, it tells the compiler this method is class method. That means you can not access this method without creating it's object. +In Python you can define the classes using $class$ keyword. Inside the class you can define the methods which are class methods. To define the methods are related to the class, first argument passed is $self$, it tells the compiler this method is class method. That means you can not access this method without creating it's object. \begin{lstlisting} >>> class math_op(): @@ -1010,7 +1010,7 @@ \subsubsection{Default Constructors} m = math_op() \end{lstlisting} -In above program $m$ is the object which we created of the class $math \textunderscore op$. As soon as object got created that time $\textunderscore\textunderscore init\textunderscore\textunderscore()$ method got called. +In above program $m$ is the object which we created of the class $math \textunderscore op$. As soon as object got created that time $\textunderscore\textunderscore init\textunderscore\textunderscore()$ method got called. If you run the above program, then it will give an output like: \begin{lstlisting} Init is called @@ -1036,7 +1036,7 @@ \subsection{Magic Methods} \paragraph{} Magic methods are the methods which are used to play with the object. Recently we saw one example of Magic methods which is $\textunderscore\textunderscore init \textunderscore\textunderscore()$. -Earlier we saw that we can add two objects like int, str, list etc... Now let's implement it. +Earlier we saw that we can add two objects like int, str, list etc... Now let's implement it. \begin{lstlisting} >>> class Human(): ... def __init__(self, name): @@ -1049,26 +1049,26 @@ \subsection{Magic Methods} >>> h + h1 'Jon Doe' >>> -\end{lstlisting} -In above example we created one class and override the $\textunderscore\textunderscore add \textunderscore\textunderscore()$ magic method. This method will get called when we are going to add two objects. When we created the objects $h$ and $h1$ that time they are the objects of the same class. So we know that both of them have the same properties. Now let's add them. +\end{lstlisting} +In above example we created one class and override the $\textunderscore\textunderscore add \textunderscore\textunderscore()$ magic method. This method will get called when we are going to add two objects. When we created the objects $h$ and $h1$ that time they are the objects of the same class. So we know that both of them have the same properties. Now let's add them. \paragraph{} When we are adding them first object's $add$ method get called and by default constructor will pass $h1$ object as $obj$ in the add method of the Human class. Using the same way you can override the other methods too: \begin{itemize} -\item $\textunderscore\textunderscore add \textunderscore\textunderscore()$ Add two objects -\item $\textunderscore\textunderscore sub \textunderscore\textunderscore()$ Subtract two objects -\item $\textunderscore\textunderscore mul \textunderscore\textunderscore()$ Multiply two objects -\item $\textunderscore\textunderscore div \textunderscore\textunderscore()$ Divide two objects -\item $\textunderscore\textunderscore lt \textunderscore\textunderscore()$ check less than condition $ a < b$ -\item $\textunderscore\textunderscore gt \textunderscore\textunderscore()$ Check grater than condition $ a > b$ -\item $\textunderscore\textunderscore le \textunderscore\textunderscore()$ Check less than and equal to condition $ a <= b$ -\item $\textunderscore\textunderscore ge \textunderscore\textunderscore()$ Check grater than and equal to condition $a >= b$ -\item $\textunderscore\textunderscore repr \textunderscore\textunderscore()$ Object representation on the console. -\item $\textunderscore\textunderscore str \textunderscore\textunderscore()$ Object representation when we are using $print()$ -\item $\textunderscore\textunderscore len \textunderscore\textunderscore()$ To Count the length of the object. (Uses with $len()$) -\item $\textunderscore\textunderscore dir \textunderscore\textunderscore()$ Return the methods associated with the class. (Uses with $dir()$) + \item $\textunderscore\textunderscore add \textunderscore\textunderscore()$ Add two objects + \item $\textunderscore\textunderscore sub \textunderscore\textunderscore()$ Subtract two objects + \item $\textunderscore\textunderscore mul \textunderscore\textunderscore()$ Multiply two objects + \item $\textunderscore\textunderscore div \textunderscore\textunderscore()$ Divide two objects + \item $\textunderscore\textunderscore lt \textunderscore\textunderscore()$ check less than condition $ a < b$ + \item $\textunderscore\textunderscore gt \textunderscore\textunderscore()$ Check grater than condition $ a > b$ + \item $\textunderscore\textunderscore le \textunderscore\textunderscore()$ Check less than and equal to condition $ a <= b$ + \item $\textunderscore\textunderscore ge \textunderscore\textunderscore()$ Check grater than and equal to condition $a >= b$ + \item $\textunderscore\textunderscore repr \textunderscore\textunderscore()$ Object representation on the console. + \item $\textunderscore\textunderscore str \textunderscore\textunderscore()$ Object representation when we are using $print()$ + \item $\textunderscore\textunderscore len \textunderscore\textunderscore()$ To Count the length of the object. (Uses with $len()$) + \item $\textunderscore\textunderscore dir \textunderscore\textunderscore()$ Return the methods associated with the class. (Uses with $dir()$) \end{itemize} \section{Inheritance} \section{File Operations} From 0992ae229e05457864ae6b4211df0012d8ecdeed Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Tue, 31 Mar 2020 01:12:23 +0530 Subject: [PATCH 6/7] Artifcat upload action --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b61c444..70380f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,13 +13,17 @@ jobs: - name: Check Indentation run: make indent - - name: Syntex Checks + - name: Syntex Suggetions run: make checks - - name: build PDFLaTeX + - name: Build PDFLaTeX run: make build - name: Analysis (git diff) if: failure() run: git diff + - uses: actions/upload-artifact@v1 + with: + name: artifacts + path: . From 18b02557f8babfd3a5b1d6ca22f1663f1489a61a Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Tue, 31 Mar 2020 01:33:54 +0530 Subject: [PATCH 7/7] remove travis completly --- .github/workflows/main.yml | 2 +- .travis.yml | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70380f7..129a0f8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: - name: Check Indentation run: make indent - - name: Syntex Suggetions + - name: Syntex Suggestions run: make checks - name: Build PDFLaTeX diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0d955e7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -dist: xenial -sudo: required - -services: - - docker - -script: - - make indent - - make checks - - make build - -after_failure: - - git diff