#Python Python 101 : Context managers - "with" expression - Context managers give you a way to allocate and release resources depending on your need s. To define context managers we make use of the the expressio June 26, 2023 Share
#Python Python 101 : The " __name__ = 'main()' " expression Sometimes, for some reasons, we may want our code to run from the main program, not from imported code using the " import " syntax. Before runn June 20, 2023 Share
#Python Python 101 : Different ways of looping over lists The " for " loop is used to iterate over the elements an " iterable " python object, for example - string, list, tuple -. We have below June 13, 2023 Share
#Python Python 101 : The "yield" instruction and its generator The " yield " instruction must "live" within a function. When a function that contains a " yield " statement is called, the June 06, 2023 Share
#Python Python 101 : Handling errors - Making your own exceptions - We create a class that inherits from the " Exception " class. Our exception class is called " OurException " and it is raised when a v May 31, 2023 Share
#Python Python 101 : The "@property" decorator for classes -Setter and Getter methods - The " @property " refers to a python decorator - a function that adds functionalities to another function without modifying its code -. The &qu May 22, 2023 Share
#Python Python 101 : Class methods If a method has a @classmethod decorator, then it is a class method . A class method has as its first argument " cls " which refers to the class May 17, 2023 Share
#Python Python 101 : Parent and children classes - __init__(), super() - For our example, we define a class called " Member ": We subclass our class " Member " as below: Defining __init__() in our subclass wi May 10, 2023 Share
#Python Python 101 : The __setattr__() function and __dict__ object The __setattr__() method is called in the background when we assign an attribute to a python object. Below is our example, the " C ar " class: We s May 03, 2023 Share
#Python Python 101 : Accessing private attributes using the "property()" function To be able to access the attributes of a class while keeping these attributes safe from any unintended modification, we can to use properties . One way April 24, 2023 Share
#Python Python 101 : Closures Closures are simply inner functions that could access variables from the enclosing function. Closures keep track of the enclosing function's varia April 18, 2023 Share
#Python Python 101 : Special functions and attributes - __dict__, __dir__, __doc__, ... - We have for example a class named " a " with no defined functions: The dir() function prints the methods and attributes - inherited from the o April 12, 2023 Share
#Python Python 101 : The "__str__()" function - String representation of an object - The __str__() function is called to give us the string representation of an object, it is called when we call the print() function on an object for ex April 05, 2023 Share
#Python Python 101 : Using the "next()" function to exit a loop - reading from a file - We use the StopIteration error in order to end an iteration as below: Sometimes we want to instruct the next() method to return a value that would tell April 03, 2023 Share
#Python Python 101 : Manually setting up a context manager Context managers make it possible for us to manage our resources. When python enters a context , it calls the __enter__() methods and it calls the __exit March 30, 2023 Share
#Python Python 101 : List and tuple comprehension A list is an aggregate of elements enclosed in brackets. A list comprehension is constituted of: an expression. a for loop. an if clause within the loop March 27, 2023 Share
#Python Python 101 : Merging dictionaries Below is one of the ways that we could use to combine two dictionaries into one: We could even use more than two dictionaries as we can see in the belo March 24, 2023 Share
#Python Python 101 : Generators Iterators loop over existing elements in a list for example. Generators generate elements as we ask for them, which helps us not overload the memory in March 23, 2023 Share
#Python Python 101 : From dictionaries to lists Below are a couple of examples of how to turn a dictionary into a list . Our first example used the items() method for form a list as we see below: Our s March 20, 2023 Share
#Python Python 101 : Local and Global variable - locals(), globals() - Sometimes, we lose track of our variables inside big chunks of code. Python gives us the possibility to display variables depending on their namespace March 15, 2023 Share
#Python Python 101 : Dictionaries - keys with multiple values - A dictionary usually maps a key to one value . Sometimes, we need a key to be linked to multiple values . We could do that using lists as you can see be March 13, 2023 Share
#Python Python 101 : Ways of printing a dictionary values. For example, we have the below dictionary " d ". We could print the values of our dictionary , using the below code: Or by using this variation: March 10, 2023 Share