Author: admin
-
Python Object-oriented Programming
Summary: in this tutorial, you’ll learn object-oriented programming in Python, including essential concepts such as objects, classes, attributes, methods, inheritances, overriding methods, etc. Introduction to Python Object-oriented Programming Everything in Python is an object. An object has a state and behaviors. To create an object, you define a class first. And then, from the class,…
-
Python __name__
Summary: in this tutorial, you’ll learn about the Python __name__ variable and how to use it effectively in modules. What’s Python __name__? If you have gone through Python code, you’ve likely seen the __name__ variable like the following: And you might wonder what the __name__ variable is. Since the __name__ variable has double underscores at both sides, it’s called dunder name. The dunder stands for double underscores…
-
Python Module Search Path
Summary: in this tutorial, you’ll learn how the module search path works in Python when you import a module into a program. Introduction to Python module search path When you import a module in a program: Python will search for the module.py file from the following sources: Python stores the resulting search path in the sys.path variable that comes from the sys module.…
-
Python Modules
Summary: in this tutorial, you’ll learn about Python modules, how to import objects from a module, and how to develop your modules. Introduction to Python modules A module is a piece of software that has a specific functionality. A Python module is a file that contains Python code. For example, when building a shopping cart…
-
Python for else
Summary: in this tutorial, you’ll learn about the Python for else statement and how to use it effectively. Introduction to the Python for else statement In Python, the for statement can have an optional else clause, which you may not be familiar with especially if you’re coming from other languages such as Java or C#. The following shows the syntax of…
-
Python try…except…else
Summary: in this tutorial, you’ll learn how to use the Python try…except…else statement. Introduction to the Python try…except…else statement The try statement has an optional else clause with the following syntax: The try…except…else statement works as follows: When you include the finally clause, the else clause executes after the try clause and before the finally clause. Python try…except…else statement examples Let’s take some examples of using the try…except…else statement. 1) Using try…except…else statement…
-
Python try…except
Summary: in this tutorial, you’ll learn how to use the Python try…except statement to handle exceptions gracefully. In Python, there’re two main kinds of errors: syntax errors and exceptions. Syntax errors When you write an invalid Python code, you’ll get a syntax error. For example: If you attempt to run this code, you’ll get the following error:…
-
Python try…except
Summary: in this tutorial, you’ll learn how to use the Python try…except statement to handle exceptions gracefully. In Python, there’re two main kinds of errors: syntax errors and exceptions. Syntax errors When you write an invalid Python code, you’ll get a syntax error. For example: If you attempt to run this code, you’ll get the following error:…
-
Python Disjoint Sets
Summary: in this tutorial, you’ll learn about disjoint sets and how to use the Python isdisjoint() method to check if two sets are disjoint. Introduction to Python disjoint sets Two sets are disjoint when they have no elements in common. In other words, two disjoint sets are sets whose intersection is an empty set. For example, the {1,3,5} and {2,4,6} sets are disjoint because they…
-
Python issuperset
Summary: in this tutorial, you’ll learn how to use the Python issuperset() method to check if a set is a superset of another. Introduction to Python issuperset method Suppose that you have two sets: A and B. Set A is a superset of set B if all elements of set B are elements of set A. If set A…