From e5fbf503b75c0881a309bd26dc7e40a3ed77c2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2EYasoob=20Ullah=20Khalid=20=E2=98=BA?= Date: Tue, 19 May 2020 17:48:13 -0400 Subject: [PATCH 01/22] Got the internship <3 --- _templates/breadcrumbs.html | 5 ----- 1 file changed, 5 deletions(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index 952fb30..a988ecd 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -26,11 +26,6 @@
-
-

Note

-

Hi! My name is Yasoob. I am the author of this book. Last year you guys helped me find an internship. I am asking for your help again to find an amazing internship for summer 2020. If you work at an amazing company and can help me, please read this article to find the details. Thanks!

-
-
+ + From 6d28d4f4e5d02811f29f6ae99a6d2d71d4e3874e Mon Sep 17 00:00:00 2001 From: Pablo Navarro Date: Tue, 9 Jun 2020 15:06:12 -0700 Subject: [PATCH 08/22] Update ternary_operators.rst (#208) Fix the blueprint for the ternary operator --- ternary_operators.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ternary_operators.rst b/ternary_operators.rst index 18b35c6..6f9cbbc 100644 --- a/ternary_operators.rst +++ b/ternary_operators.rst @@ -12,7 +12,7 @@ expressions. .. code:: python - condition_if_true if condition else condition_if_false + value_if_true if condition else value_if_false **Example:** From 6ed9f4542e2ec28343ac21932132c322f3af400a Mon Sep 17 00:00:00 2001 From: Yasoob Date: Thu, 11 Jun 2020 16:14:39 -0400 Subject: [PATCH 09/22] removed shynet. Too many fake views --- _templates/breadcrumbs.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a110d90..a988ecd 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -80,5 +80,3 @@ {% endif %}
- - From 23f165f7fcb0c28c8dffc94b18b79a9611b122bc Mon Sep 17 00:00:00 2001 From: Yasoob Date: Thu, 11 Jun 2020 16:26:20 -0400 Subject: [PATCH 10/22] maybe plausible analytics works better? --- _templates/breadcrumbs.html | 1 + 1 file changed, 1 insertion(+) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a988ecd..247493d 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -79,4 +79,5 @@ {% endif %}
+ From e7bbb9bbe26cc9076bdb5201c1c5c5f338b70479 Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Tue, 16 Jun 2020 23:51:48 -0400 Subject: [PATCH 11/22] grammar: add an apostrophe (#209) --- args_and_kwargs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/args_and_kwargs.rst b/args_and_kwargs.rst index 544742e..34b4758 100644 --- a/args_and_kwargs.rst +++ b/args_and_kwargs.rst @@ -6,7 +6,7 @@ figuring out the \*args and \*\*kwargs magic variables. So what are they ? First of all let me tell you that it is not necessary to write \*args or \*\*kwargs. Only the ``*`` (asterisk) is necessary. You could have also written \*var and \*\*vars. Writing \*args and \*\*kwargs is just a -convention. So now lets take a look at \*args first. +convention. So now let's take a look at \*args first. Usage of \*args ^^^^^^^^^^^^^^^ From a4d1ec1b1a2c979ca71fdff9ab50cb4fb48d1bfc Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Sat, 4 Jul 2020 20:08:37 -0400 Subject: [PATCH 12/22] add output for first example (#211) --- enumerate.rst | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/enumerate.rst b/enumerate.rst index 277b679..e765ed5 100644 --- a/enumerate.rst +++ b/enumerate.rst @@ -7,12 +7,19 @@ advanced programmers are unaware of it. It allows us to loop over something and have an automatic counter. Here is an example: .. code:: python + + my_list = ['apple', 'banana', 'grapes', 'pear'] + for counter, value in enumerate(my_list): + print counter, value - for counter, value in enumerate(some_list): - print(counter, value) + # Output: + # 0 apple + # 1 banana + # 2 grapes + # 3 pear -And there is more! ``enumerate`` also accepts an optional argument which -makes it even more useful. +And there is more! ``enumerate`` also accepts an optional argument that +allows us to specify the starting index of the counter. .. code:: python @@ -26,9 +33,9 @@ makes it even more useful. # 3 grapes # 4 pear -The optional argument allows us to tell ``enumerate`` from where to -start the index. You can also create tuples containing the index and -list item using a list. Here is an example: +An example of where the optional argument of ``enumerate``comes in handy +is creating tuples containing the index and list item using a list. Here +is an example: .. code:: python From 1593256bcd5b4d0f7ced67460b2906475a2fc31f Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Fri, 10 Jul 2020 13:55:59 -0400 Subject: [PATCH 13/22] make exception execution more specific (#212) --- exceptions.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exceptions.rst b/exceptions.rst index d6fae82..abdb571 100644 --- a/exceptions.rst +++ b/exceptions.rst @@ -5,9 +5,11 @@ Exception handling is an art which once you master grants you immense powers. I am going to show you some of the ways in which we can handle exceptions. -In basic terminology we are aware of ``try/except`` clause. The code -which can cause an exception to occur is put in the ``try`` block and +In basic terminology we are aware of the ``try/except`` structure. The code +that can cause an exception to occur is put in the ``try`` block and the handling of the exception is implemented in the ``except`` block. +The code in the ``except`` block will only execute if the ``try`` block +runs into an exception. Here is a simple example: .. code:: python From 7ca139de480aaee0fedb8df3e3a533b7ded37eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2EYasoob=20Ullah=20Khalid=20=E2=98=BA?= Date: Sat, 11 Jul 2020 14:24:46 -0400 Subject: [PATCH 14/22] Removed Plausible --- _templates/breadcrumbs.html | 1 - 1 file changed, 1 deletion(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index 247493d..a988ecd 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -79,5 +79,4 @@ {% endif %}
- From 2002172addd3cdf3be5b39514783b3a617b2de50 Mon Sep 17 00:00:00 2001 From: oliverkoo Date: Wed, 15 Jul 2020 14:40:21 -0400 Subject: [PATCH 15/22] Update enumerate.rst (#214) add missing space --- enumerate.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enumerate.rst b/enumerate.rst index e765ed5..3bcd2f6 100644 --- a/enumerate.rst +++ b/enumerate.rst @@ -33,7 +33,7 @@ allows us to specify the starting index of the counter. # 3 grapes # 4 pear -An example of where the optional argument of ``enumerate``comes in handy +An example of where the optional argument of ``enumerate`` comes in handy is creating tuples containing the index and list item using a list. Here is an example: From 42fec672382bc4e05d81559f6031671b1e617dee Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Mon, 20 Jul 2020 19:43:13 -0400 Subject: [PATCH 16/22] changed wording on *args (#210) * changed wording * Update args_and_kwargs.rst --- args_and_kwargs.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/args_and_kwargs.rst b/args_and_kwargs.rst index 34b4758..85ed174 100644 --- a/args_and_kwargs.rst +++ b/args_and_kwargs.rst @@ -3,7 +3,7 @@ I have come to see that most new python programmers have a hard time figuring out the \*args and \*\*kwargs magic variables. So what are they -? First of all let me tell you that it is not necessary to write \*args +? First of all, let me tell you that it is not necessary to write \*args or \*\*kwargs. Only the ``*`` (asterisk) is necessary. You could have also written \*var and \*\*vars. Writing \*args and \*\*kwargs is just a convention. So now let's take a look at \*args first. @@ -12,12 +12,11 @@ Usage of \*args ^^^^^^^^^^^^^^^ \*args and \*\*kwargs are mostly used in function definitions. \*args -and \*\*kwargs allow you to pass a variable number of arguments to a -function. What variable means here is that you do not know beforehand -how many arguments can be passed to your function by the user -so in this case you use these two keywords. \*args is used to send a -**non-keyworded** variable length argument list to the function. Here's -an example to help you get a clear idea: +and \*\*kwargs allow you to pass an unspecified number of arguments to a +function, so when writing the function definition, you do not need to +know how many arguments will be passed to your function. \*args is used to +send a **non-keyworded** variable length argument list to the function. +Here's an example to help you get a clear idea: .. code:: python From 219193a04c9d3fa52a5926467776c4ec47a5e204 Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Mon, 20 Jul 2020 19:44:07 -0400 Subject: [PATCH 17/22] add details about catching all exceptions (#213) * add details about catching all exceptions * Small grammar/wording changes --- exceptions.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exceptions.rst b/exceptions.rst index abdb571..ebeb0d5 100644 --- a/exceptions.rst +++ b/exceptions.rst @@ -62,8 +62,16 @@ trapping ALL exceptions: # Some logging if you want raise e -This can be helpful when you have no idea about the exceptions which may -be thrown by your program. +This can be helpful when you have no idea about the exceptions that may +be thrown by your program. If you are just looking to catch all execptions, +but don't actually care about what they are, you can even exclude the +``Exception as e`` part. + +Note:: catching all exceptions may have unintended consequences because catching +all exceptions may also catch the ones you want to occur; for example, in +many command-line based programs, pressing control+c will terminate the program, +but if you catch all excepts, the ``KeyboardInterrupt`` will be caught as an +exception, so pressing control+c will NOT terminate the program. ``finally`` clause ~~~~~~~~~~~~~~~~~~ From a5c450968b100561d3ce411463161f101982af61 Mon Sep 17 00:00:00 2001 From: Jordan Bonecutter <34787245+jordan-bonecutter@users.noreply.github.com> Date: Sun, 16 Aug 2020 20:33:46 -0700 Subject: [PATCH 18/22] Unnecessary #include statement (#216) No stdio functions were used in this file. --- python_c_extension.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/python_c_extension.rst b/python_c_extension.rst index 5f49c3b..f4cf5d4 100644 --- a/python_c_extension.rst +++ b/python_c_extension.rst @@ -36,8 +36,6 @@ Simple C code to add two numbers, save it as ``add.c`` //sample C file to add 2 numbers - int and floats - #include - int add_int(int, int); float add_float(float, float); From 13764ad2b2e848495b567910770e7a25dd72ea92 Mon Sep 17 00:00:00 2001 From: Yasoob Khalid Date: Thu, 20 Aug 2020 01:11:21 -0400 Subject: [PATCH 19/22] new book released --- _templates/breadcrumbs.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a988ecd..f3f3b94 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -25,7 +25,14 @@ {% endif %}
- +
+

New book released!

+

Hi! I just released the alpha version of my new book; Practical Python Projects. + Learn more about it + on my blog. In 325+ pages, I will teach you how to implement 12 end-to-end projects. + You can buy it from Feldroy.com. +

+
    {% block breadcrumbs %}
  • {{ _('Docs') }} »
  • From 0bc5da8d01ddfc766297e82dd106ff3549eac67c Mon Sep 17 00:00:00 2001 From: John <66183716+just-linux@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:40:24 -0500 Subject: [PATCH 20/22] Correct minor underline build complaints (#219) * Correct minor underline build complaints * Correct minor underline build complaints, additional file --- context_managers.rst | 2 +- decorators.rst | 4 ++-- for_-_else.rst | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/context_managers.rst b/context_managers.rst index 5a0f9d0..261ebd6 100644 --- a/context_managers.rst +++ b/context_managers.rst @@ -36,7 +36,7 @@ Let's see how we can implement our own Context Manager. This should allow us to understand exactly what's going on behind the scenes. Implementing a Context Manager as a Class: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ At the very least a context manager has an ``__enter__`` and ``__exit__`` method defined. Let's make our own file-opening Context diff --git a/decorators.rst b/decorators.rst index 3389728..30509fe 100644 --- a/decorators.rst +++ b/decorators.rst @@ -273,7 +273,7 @@ Now let's take a look at the areas where decorators really shine and their usage makes something really easy to manage. Authorization -~~~~~~~~~~~~ +~~~~~~~~~~~~~ Decorators can help to check whether someone is authorized to use an endpoint in a web application. They are extensively used in Flask web @@ -296,7 +296,7 @@ authentication: return decorated Logging -~~~~~~~~~~~~ +~~~~~~~ Logging is another area where the decorators shine. Here is an example: diff --git a/for_-_else.rst b/for_-_else.rst index 9a68363..f7fbe82 100644 --- a/for_-_else.rst +++ b/for_-_else.rst @@ -1,5 +1,5 @@ ``for/else`` ----------- +------------ Loops are an integral part of any language. Likewise ``for`` loops are an important part of Python. However there are a few things which most @@ -22,7 +22,7 @@ That is the very basic structure of a ``for`` loop. Now let's move on to some of the lesser known features of ``for`` loops in Python. ``else`` Clause -^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^ ``for`` loops also have an ``else`` clause which most of us are unfamiliar with. The ``else`` clause executes after the loop completes normally. From 9b6262eed638dd2f5960fb959def6fe981b0b40c Mon Sep 17 00:00:00 2001 From: Keith Kong Hei Lok <70051933+LittleBigKeith@users.noreply.github.com> Date: Mon, 21 Sep 2020 01:31:31 +0800 Subject: [PATCH 21/22] Create zip.md (#218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create zip.md Create new file for 'zip' function * Converted to reStructured * added zip to the index Co-authored-by: M.Yasoob Ullah Khalid ☺ Co-authored-by: Yasoob Khalid --- index.rst | 1 + zip.rst | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 zip.rst diff --git a/index.rst b/index.rst index 224ae75..b45de64 100644 --- a/index.rst +++ b/index.rst @@ -50,6 +50,7 @@ Table of Contents virtual_environment collections enumerate + zip object_introspection comprehensions exceptions diff --git a/zip.rst b/zip.rst new file mode 100644 index 0000000..947fe2a --- /dev/null +++ b/zip.rst @@ -0,0 +1,71 @@ +Zip and unzip +------------- + +**Zip** + +Zip is a useful function that allows you to combine two lists easily. + +After calling zip, an iterator is returned. In order to see the content wrapped inside, we need to first convert it to a list. + +Example: + +.. code:: python + + first_name = ['Joe','Earnst','Thomas','Martin','Charles'] + + last_name = ['Schmoe','Ehlmann','Fischer','Walter','Rogan','Green'] + + age = [23, 65, 11, 36, 83] + + print(list(zip(first_name,last_name, age))) + + # Output + # + # [('Joe', 'Schmoe', 23), ('Earnst', 'Ehlmann', 65), ('Thomas', 'Fischer', 11), ('Martin', 'Walter', 36), ('Charles', 'Rogan', 83)] + +One advantage of zip is that it improves readability of for loops. + +For example, instead of needing multiple inputs, you only need one zipped list for the following for loop: + +.. code:: python + + first_name = ['Joe','Earnst','Thomas','Martin','Charles'] + last_name = ['Schmoe','Ehlmann','Fischer','Walter','Rogan','Green'] + age = [23, 65, 11, 36, 83] + + for first_name, last_name, age in zip(first_name, last_name, age): + print(f"{first_name} {last_name} is {age} years old") + + # Output + # + # Joe Schmoe is 23 years old + # Earnst Ehlmann is 65 years old + # Thomas Fischer is 11 years old + # Martin Walter is 36 years old + # Charles Rogan is 83 years old + +**Unzip** + +We can use the `zip` function to unzip a list as well. This time, we need an input of a list with an asterisk before it. + +The outputs are the separated lists. + +Example: + +.. code:: python + + full_name_list = [('Joe', 'Schmoe', 23), + ('Earnst', 'Ehlmann', 65), + ('Thomas', 'Fischer', 11), + ('Martin', 'Walter', 36), + ('Charles', 'Rogan', 83)] + + first_name, last_name, age = list(zip(*full_name_list)) + print(f"first name: {first_name}\nlast name: {last_name} \nage: {age}") + + # Output + + # first name: ('Joe', 'Earnst', 'Thomas', 'Martin', 'Charles') + # last name: ('Schmoe', 'Ehlmann', 'Fischer', 'Walter', 'Rogan') + # age: (23, 65, 11, 36, 83) + From 257709f4acb61539bf654fc6a5b72ac5e2c86ba0 Mon Sep 17 00:00:00 2001 From: absara <105458799+Abidi-S@users.noreply.github.com> Date: Fri, 18 Nov 2022 07:42:25 +0000 Subject: [PATCH 22/22] Global and Return edits (#232) * replaced "&" with "and" in article heading * fixed minor typos --- global_&_return.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/global_&_return.rst b/global_&_return.rst index 39a75d4..0661752 100644 --- a/global_&_return.rst +++ b/global_&_return.rst @@ -1,9 +1,9 @@ -Global & Return +Global and Return --------------- -You might have encountered some functions written in python which have a +You might have encountered some functions written in Python which have a ``return`` keyword in the end of the function. Do you know what it does? It -is similar to return in other languages. Lets examine this little +is similar to return in other languages. Let's examine this little function: .. code:: python @@ -15,7 +15,7 @@ function: print(result) # Output: 8 -The function above takes two values as input and then output their +The function above takes two values as input and then outputs their addition. We could have also done: .. code:: python @@ -28,11 +28,11 @@ addition. We could have also done: print(result) # Output: 8 -So first lets talk about the first bit of code which involves the +So first let's talk about the first bit of code which involves the ``return`` keyword. What that function is doing is that it is assigning the value to the variable which is calling that function which in our -case is ``result``. In most cases and you won't need to use the -``global`` keyword. However lets examine the other bit of code as well +case is ``result``. In most cases you won't need to use the +``global`` keyword. However, let's examine the other bit of code as well which includes the ``global`` keyword. So what that function is doing is that it is making a global variable ``result``. What does global mean here? Global variable means that we can access that variable outside the @@ -125,11 +125,11 @@ Or by more common convention: print(profile_age) # Output: 30 -Keep in mind that even in the above example we are returning a tuple (despite the lack of paranthesis) and not separate multiple values. If you want to take it one step further, you can also make use of `namedtuple `_. Here is an example: +Keep in mind that even in the above example we are returning a tuple (despite the lack of parenthesis) and not separate multiple values. If you want to take it one step further, you can also make use of `namedtuple `_. Here is an example: .. code:: python - from collections import namedtuple + from collections import namedtuple def profile(): Person = namedtuple('Person', 'name age') return Person(name="Danny", age=31) @@ -157,4 +157,4 @@ Keep in mind that even in the above example we are returning a tuple (despite th print(age) #31 -This is a better way to do it along with returning ``lists`` and ``dicts``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them. +This is a better way to do it, along with returning ``list`` and ``dict``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them.