Monthly Archives: October 2021

29. RegEx Or Regular Expressio

A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern. RegEx Module Python has a built-in package called re, which can be used to work with Regular Expressions. Import the re module:import re RegEx in Python When you have imported… Read More »

28. JSON

JSON is a syntax for storing and exchanging data. JSON is text, written with JavaScript object notation. JSON in Python Python has a built-in package called json, which can be used to work with JSON data. Example Import the json module:import json Parse JSON – Convert from JSON to Python If you have a JSON string, you… Read More »

27. Math

Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers. Built-in Math Functions The min() and max() functions can be used to find the lowest or highest value in an iterable: Example x = min(5, 10, 25)y = max(5, 10, 25) print(x)print(y) Output:525 The abs() function returns the absolute (positive) value of the specified number:… Read More »

26. Datetime

Python Dates A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects. Example Import the datetime module and display the current date:import datetime x = datetime.datetime.now()print(x) Output:2021-10-06 09:57:24.627387 Date Output When we execute the code from the example above the result… Read More »

25. Modules

What is a Module? Consider a module to be the same as a code library. A file containing a set of functions you want to include in your application. Create a Module To create a module just save the code you want in a file with the file extension .py: Example Save this code in a… Read More »

24. Scope

A variable is only available from inside the region it is created. This is called scope. Local Scope A variable created inside a function belongs to the local scope of that function, and can only be used inside that function. Example A variable created inside a function is available inside that function:def myfunc():  x = 300  print(x)myfunc() Output:300 Function Inside Function… Read More »

23. Iterators

Python Iterators An iterator is an object that contains a countable number of values. An iterator is an object that can be iterated upon, meaning that you can traverse through all the values. Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__(). Iterator vs Iterable Lists,… Read More »

22. Inheritance

Python Inheritance Inheritance allows us to define a class that inherits all the methods and properties from another class. Parent class is the class being inherited from, also called base class. Child class is the class that inherits from another class, also called derived class. Create a Parent Class Any class can be a parent class, so… Read More »

21. Classes and Objects

Python Classes/Objects Python is an object oriented programming language. Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a “blueprint” for creating objects. Create a Class To create a class, use the keyword class: Example Create a class named MyClass, with a property named x:class MyClass: … Read More »

20. Arrays

Note: Python does not have built-in support for Arrays, but Python Lists can be used instead. Arrays Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library. Arrays are used to store multiple values in one single variable: Example Create an… Read More »