Author name: Vikram Chiluka

Python subprocess Module with Examples

subprocess Module:

Generally, we develop Python code to automate a process or to obtain results without requiring manual intervention via a UI form or any data-related form. But what if we need system-level information for a specific task or functionality? How do we handle system-level scripts in Python?

This is where the Python subprocess module comes into play.

The subprocess module implements several functions for running system-level scripts within the Python environment:

  • subprocess.call()
  • subprocess.run()
  • subprocess.check_output()
  • subprocess.Popen() and communicate() functions

1)subprocess.call():

To use the functions associated with the subprocess module, we must first import it into the Python environment.

The subprocess.call() function executes the command specified as arguments and returns whether the code was successfully performed or not.

Syntax:

subprocess.call(arguments , shell= True)

Example1:

In the following example, we attempt to run “echo btechgeeks” using Python scripting.

Similarly, with the call() function, the first parameter (echo) is treated as the executable command, and the arguments following the first are treated as command-line arguments.

Also, we must provide shell = True in order for the parameters to be interpreted as strings. When False is set, the arguments are interpreted as a path or file paths.

Approach:

  • Import subprocess module using the import keyword.
  • Pass “echo”, some random string, shell = True/False as the arguments to the call() function and store it in a variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import subprocess module using the import keyword
import subprocess
# Pass "echo", some random string, shell = True/False as the arguments to the call()
# function and store it in a variable.
rslt = subprocess.call(["echo", "btechgeeks"], shell=True)
# Print the above result
print(rslt)

Output:

It returns 0 as the return code, as shown below. Any other value returned by the code indicates that the command execution was unsuccessful.

"btechgeeks" 
0

Example2:

In this example, we used the Python script to run the command “ls -l.”

# Import subprocess module using the import keyword
import subprocess
rslt = subprocess.call(["ls","-l"],shell=True)
print(rslt)

Output:

0
-rw-r--r-- 1 smulani 1049033 Feb 27 10:40 check.py

2)subprocess.run():

As seen above, the call() function simply returns the code of the command executed. It does not enable us in performing a check on the input and check parameters.

For this, we have the subprocess.run() function, which allows us to execute the bash or system script within the python code and returns the command’s return code.

Additionally, it returns the arguments supplied to the function. This allows us to check the inputs to the system scripts.

For Example:

# Import subprocess module using the import keyword
import subprocess
# Pass a "echo", some random string, shell = True/False as the arguments to the run()
# function and store it in a variable.
rslt = subprocess.run(["echo", "btechgeeks"], shell=True)
# Print the above result
print(rslt)

Output:

'btechgeeks'
CompletedProcess(args=['echo', 'btechgeeks'], returncode=0)

3)subprocess.Popen() function:

The subprocess.Popen() function allows us to run child programs as a new process internally. This can also be used to run shell commands from within Python.

Syntax:

subprocess.Popen(arguments, stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)

stdout: The output returned from the command
stderr: The error returned from the command

Example:

# Import subprocess module using the import keyword
import subprocess
process = subprocess.Popen(
    ['echo', 'btechgeeks'],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
print(stdout)

Output:

b'"btechgeeks"\r\n'

We’ve also used the communicate() method here. This function allows us to read and retrieve the input, output, and error data of the script that was executed directly from the process, as shown above.

Python subprocess Module with Examples Read More »

Python Bit Functions on Integer

Bit Functions in Python:

Before we begin with Python bit functions for integers, let us first understand their interconversion.

Conversion of data values enters the picture when we are either automating a manual procedure or working with system-level information.

While dealing with data in various numeric forms such as hexadecimal, numeric, octal, and so on, bit functions play a crucial part in analyzing the bit level data of integers.

Python provides the following collection of bit level methods to assist us evaluate integer data in terms of bit level information and representation:

  • bit_length() function
  • to_bytes() function
  • int.from_bytes() function

Bit Functions on Integer in Python

1)bit_length() function:

int.bit_length() returns the number of bits needed to represent an integer in binary, ignoring the sign and leading zeros.

For example:

Let the Number = 2 

Its binary representation = 0010.

The actual length of its binary representation  = 4

But the int.bit_length() function returns the output = 2

It excludes or ignores the two leading zeroes, it only counts the non-zero places and returns the length as 2.

Hence the output = 2

2) Number = -7

However, because the function ignores the sign value, it handles it as if it were any other positive integer.

Output = 3

1)For Example

Approach:

  • Give the number as static input and store it in a variable.
  • Apply bit_length() function on the given number that returns the number of bits needed to represent an integer in binary, ignoring the sign and leading zeros.
  • Store it in another variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Give the number as static input and store it in a variable.
gvn_numb = 2
# Apply bit_length() function on the given number that returns the number
# of bits needed to represent an integer in binary, ignoring the sign and
# leading zeros.
# Store it in another variable.
rslt_len = gvn_numb.bit_length()
# Print the above result.
print("The result length for given number{", gvn_numb, "} =", rslt_len)

Output:

The result length for given number{ 2 } = 2
# Similarly, do for the other numbers and print the result
gvn_numb = 5
print(gvn_numb.bit_length())

gvn_numb = -7
print(gvn_numb.bit_length())

Output:

3
3

2)to_bytes() function:

Return a byte array representing an integer.

  • When byteorder is set to “big,” the most significant byte is at the start of the byte array.
  • The most important byte is at the end of the byte array if byteorder is set to “little.”

The signed argument checks if the two’s complement is used to represent the integer.

Syntax:

int.to_bytes(length, byteorder, signedorder = False)

Parameter values

length: It is the length of the resulting array.

byteorder: It may be “big” or “little”.

signedorder: When set to True, it uses two’s complement to represent the number as a bytes array.

1)For Example

# This function returns the byte representation of 1024 in big endian machine
# Here, we have expressed the integer value 1024 as a 4-byte array (length)
# with the most significant byte at the beginning of the array.
print((1024).to_bytes(4, byteorder='big'))

Output:

b'\x00\x00\x04\x00'

3)int.from_bytes() function:

This function returns the integer represented by the specified array of bytes.

In other words, the from_bytes() method accepts an array of bytes as an argument, along with the byteorder parameter, and returns the integer value corresponding to it.

Syntax:

int.from_bytes(bytes, byteorder, signed=False)

For Example:

# from_bytes() function Returns a big endian integer value of 'x00x10'.
print(int.from_bytes(b'\x00\x00\x04\x00', byteorder='big'))

Output:

1024

 

Python Bit Functions on Integer Read More »

Python geocode Module for Reverse Zipcode lookup

In this tutorial, we’ll use the geocode module to perform a reverse lookup on several zipcodes.

geocode Module:

The Python geocode module is designed to handle geographical data and help us in pairing and matching different types of data together.

Using the pgeocode module, we could retrieve and represent the region or area-related information based on zip code information.

As a result, we can use this module for our needs.

Some of the pgeocode module’s functions are listed below:

  • Data about the country/region derived from the postal code
  • The distinction between postal codes
  • Data from many postal codes are used to generate data for multiple regions.

Geo Code Enterprise Application APIs

I would recommend ZipCodeBase if you are seeking for a ZIP Code address lookup API for business apps. They give zip code data for over 200 nations, which is useful if your service serves consumers from all over the world. They feature a variety of APIs, including the postal code radius search API, which is highly handy for finding postal codes within a radius. Their documentation is excellent, and the greatest thing is that they offer a free plan that allows us to get started quickly and test the service.

Obtaining regional data from postal codes

Now we see how to get regional data from various postal codes that are offered as inputs. Using the geocode module, we can simply obtain the country code, state, name, and so on.

Syntax:

pgeocode.Nominatim(country name)
query_postal_code(postalcode)

The Nominatim() method allows us to query country names while the query_post_code() method works on the zip codes.

To begin, Install the pgeocode module as shown below:

pip install pgeocode

Output:

Collecting pgeocode Downloading pgeocode-0.3.0-py3-none-any.whl (8.5 kB)
 Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-
packages (from pgeocode) (2.23.0) Requirement already satisfied: numpy in 
/usr/local/lib/python3.7/dist-packages (from pgeocode) (1.19.5) Requirement 
already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from 
pgeocode) (1.1.5) Requirement already satisfied: pytz>=2017.2 in /usr/local/
lib/python3.7/dist-packages (from pandas->pgeocode) (2018.9) Requirement 
already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/
dist-packages (from pandas->pgeocode) (2.8.2) Requirement already satisfied: 
six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7
.3->pandas->pgeocode) (1.15.0) Requirement already satisfied: certifi>=2017.4
.17 in /usr/local/lib/python3.7/dist-packages (from requests->pgeocode)
 (2021.10.8) Requirement already satisfied: chardet<4,>=3.0.2 in /usr/
local/lib/python3.7/dist-packages (from requests->pgeocode) (3.0.4) 
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7
/dist-packages (from requests->pgeocode) (2.10) Requirement already satisfied:
urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-
packages (from requests->pgeocode) (1.24.3) Installing collected packages:
pgeocode Successfully installed pgeocode-0.3.0

For example:

Approach:

  • Import the pgeocode module using the import keyword
  • Pass some random country name to the Nominatim() function to query country given.
  • Store it in a variable.
  • Here ‘fr’ means France – to check for other country codes see the Readme list of pgeocode module.
  • Pass some random postal code to the query_postal_code() function to get the information (like country code, state, name) about the region given.
  • Store it in another variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import the pgeocode module using the import keyword
import pgeocode
# Pass some random country name to the Nominatim() function to query country given
# Store it in a variable
# Here 'fr' means France - to check for other country code see the Readme list of 
# pgeocode module
cntry_data = pgeocode.Nominatim('fr')
# Pass some random postal code to the query_postal_code() function to
# get the information (like country code, state, name) about the region given.
# Store it in another variable
rslt_info = cntry_data.query_postal_code("75013")
# Print the above result.
print(rslt_info)

Output:

postal_code              75013 
country_code             FR 
place_name               Paris 13, Paris 
state_name               Île-de-France 
state_code               11 
county_name              Paris 
county_code              75 
community_name           Paris 
community_code           751 
latitude                 48.8322 
longitude                2.35245 
accuracy                 5 
Name: 0, dtype: object

NOTE:

To check for other country codes see the Readme list of pgeocode module.
For Example US - "95014", BR for Brazil etc.

To Get Geodistance between two zip codes

Another useful feature of the geocode module is the ability to calculate the geodistance between two zip codes. We can achieve the same result by using the Geodistance() function.

Approach:

  • Import the pgeocode module using the import keyword.
  • Pass some random country name as an argument to the GeoDistance() function and store it in a variable.
  • Pass two random postal codes as the arguments to the query_postal_code() function to get the geograpical distance between the given two zipcodes.
  • Store it in another variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import the pgeocode module using the import keyword
import pgeocode
# Pass some random country name as an argument to the GeoDistance() function and
# Store it in a variable
rslt_data = pgeocode.GeoDistance('fr')
# Pass two random postal codes as the arguments to the query_postal_code() function
# to get the geograpical distance between the given two zipcodes.
# Store it in another variable
fnl_info = rslt_data.query_postal_code("75013", "69006")
# Print the above result.
print("The geograpical distance between given two postal codes = ")
print(fnl_info)

Output:

The geograpical distance between given two postal codes = 
389.2183901641009

Python geocode Module for Reverse Zipcode lookup Read More »

Differences: Python vs Julia

Python

Python is an object-oriented, high-level, multi-paradigm, interpreted programming language with dynamic semantics. Guido van Rossum invented the language in 1991 as a successor to his prior language ABC. He used all of ABC’s helpful features and syntax to build Python, a new language.
Python is also a general-purpose language with built-in high-level data structures, as well as dynamic typing, dynamic binding, and many other capabilities. Python is so well-suited for usage in Complex or Rapid Application Development, as well as as a scripting or glue language that connects components.

Python Features 

  • Simple to code and learn
  • The Python Software Foundation License makes it free and open source.
  • It is an Object-Oriented Programming Language
  • Python has GUI Programming Support
  • Python is Extensible & Portable
  • High-Level Multi-Platform Language
  • Python has large standard libraries which are in-built(built-in methods).
  • Interpreted

Julia

Julia is a computer language that is used for scientific computing and mathematical programming. Julia is a mix of C and Python, however, it does not literally copy any of the characteristics of either language. This combo combines the fast execution speed of C with the flexibility of Python code development.

Julia was created by a team of four people at MIT. It is a dynamic, high-level programming language that is open-source and used for statistical calculation and data analysis. Julia was created primarily for its programming speed; it executes code significantly faster than Python and R. Julia assists with big data analytics by handling complex tasks such as cloud computing and parallelism, both of which are critical in studying Big Data.

Python vs Julia

 

          Features           Python        Julia
         Developed ByPython was developed by Python Software FoundationJulia was developed by a team of four people at MIT
          SpeedPython, on the other hand, is fast but slower than C.Julia is faster than Python, with an execution performance that is comparable to that of C.
    Interpreted or complied?Python is an Interpreted languageJulia has Complied
       CommunityPython has been around for a long time and has a huge programming community. As a result, it is considerably easier to get your issues fixed online.Julia is a new language with a small community, therefore tools for resolving issues and problems are limited.
       Code ConversionIt is extremely tough to create Python code by converting C code or vice versa.Julia codes are simply developed by converting C or Python code.
      ParadigmOOP, POP, and Functional Paradigms   Functional
companies that use the  languageGoogle, Facebook, Spotify, Quora, Netflix, and Reddit are just a few examples.Amazon, Apple, Disney, Ford, Google, and NASA are a few examples that use Julia
Library supportPython, on the other hand, has a number of libraries, making it easier to accomplish a variety of additional jobs.Julia has a limited number of libraries to work with. It may, however, interfere with C and Fortran libraries used to handle plots.
  Type SystemPython is dynamically typed, which allows for the generation of variables without the need for type declaration. It differs from Julia only in that it is not statically typed.Julia is also a dynamically typed programming language that allows developers to create variables without having to declare their types. Julia also has the advantage of Static typing.
 

 

Array Index

Python arrays have a 0 index. Arrays are generally indexed from 0 in every language.Julia arrays are 1-indexed, which means they begin with 1-n rather than 0-n. It may present issues for programmers who are accustomed to utilizing other languages.
          DevelopmentMatured ( version – v3.9.2 )Actively Developed (version – v1.5.4)

Comparision

Performace

Julia vs Python performance takes a turn. Julia is a compiled language, which means that Julia programmes are directly executed as executable code.
As a result, Julia code is also universally executable with languages such as Python, C, R, and others. It produces outstanding, efficient, and quick results without the need for numerous optimizations and native profiling approaches. Some Julia optimizations cannot be applied in Python.
Essentially, Julia allows projects built in other languages to be written once and naively compiled, making it perfect for machine learning and data research. Julia’s time to execute large and complex codes is less than Python’s.

Python not only takes time to implement codes, but it also necessitates a number of optimization methods and additional libraries, highlighting Julia’s performance perfection.

Speed

When writing code, execution speed is an important factor. Julia’s execution speed is comparable to that of the C programming language. It was created with the intention of creating a rapid language. Julia is not an interpreted language that accelerates execution. The LLVM framework is used to build code in Julia. Julia solves performance issues that require speed without the use of manual profiling and optimization approaches. Julia is an excellent solution for challenges involving Big Data, Cloud Computing, Data Analysis, and Statistical Computing. When we compare Julia versus Python’s speed and performance, it is clear that Julia is superior.

Paradigm

Julia supports functional programming and Type hierarchy out of the box. Python enables us to be more creative in how we solve our software. Python allows for Functional, Object-Oriented, and Procedural Programming.

Reusability of Code

Julia’s code re-usability is one of its most important features. Although code re-usability is an important characteristic of Object-Oriented Programming, Julia’s type system and multiple-dispatch are more effective for code re-usability.

Libraries

Python offers a large library that simplifies Python coding by simply importing these libraries and use their functions. Julia lacks a huge library set, which is a disadvantage when compared to Python. Furthermore, Python is supported by a large number of third-party libraries.

Another problem with Julia’s libraries is that packages are not adequately maintained. Julia can communicate with libraries written in C, although plotting data takes time at first. Julia, like a new language, needs more developed libraries in order to grow.

Community

Python is a fairly popular programming language (Top 3 in 2021). It has a lot of community support, with people from all walks of life coming up with creative ways to help and support the community. Every year, the international Python programming language community hosts a number of conferences (PyCons). PyCons are held all around the world, with the majority of them organized by volunteers from local Python communities. In such community events, you may expect to see people ranging from software professionals to researchers to students.

Julia is also a very welcoming community, with individuals from various walks of life. Julia is still ascending the popularity ladder, so don’t expect a massive community like Python, but she does have a supportive one.

Tooling Support
A programming language that provides excellent tools support for any software development project is preferred by any programmer. Python outperforms Julia in terms of tooling support. It’s because Python provides excellent tooling support, whereas Julia’s tooling support is still in the works.

As a result, Julia does not have as many tools for debugging and addressing performance issues as Python does. Furthermore, because Julia is a novel language with native APIs, there is a greater risk of an unsafe interface in the case of Julia.

Differences: Python vs Julia Read More »

Python Assignment Help: Can You Put Your Trust in Someone to Handle Your Python Assignment?

If you’re waiting for an explanation to the question “Who will perform my python assignment?” you’ve come to the right place! This tutorial will explain you everything you need to know about python assignment help and why it would be a smart idea for you to use it. Learn everything there is to know about safe homework assistance services, as well as how to pick a reputable one, by reading on.

Should You Get Your Homework Online?
Should I actually hire someone to do my python homework? That’s an excellent question! There are numerous advantages to using Python homework programming assistance. Let’s look at what they are and how they can be of tremendous assistance to you:

  • It’s inexpensive. There’s no need to overpay for your homework! Online python programming assignment help is typically inexpensive and will not charge you a high fee for finished projects. Of course, different providers have varying pricing, but you should be able to find something that is within your budget. There are also other sales and discounts available online.
  • You will receive sure solutions to your assignment problem. Python assignment help can ensure that you receive the greatest possible mark for your coursework.
  • You will interact with writers who are experts in their fields. Working with specialists is always beneficial, especially when it comes to personal concerns and projects. It is possible to receive not only a wonderful solution to your problem but also fantastic guidance.
  • Your grades will improve. Programming is a difficult subject that necessitates a significant amount of time and effort. Getting good grades can be a time-consuming effort, and if you want to increase your GPA, it is always best to use all of the resources and tools available to you.
  • There will be no missed deadlines. Deadlines are one of the most difficult issues that students confront when working on their assignments. Unfortunately, most teachers are unwilling to change the deadlines and will penalize you for missing them. If you use online homework help, you can quickly handle this difficulty.
  • You’ll witness how even the most difficult tasks are performed. Learning is essential. Ordering your assignment online allows you to observe how pros handled them and learn how to complete any task on your own.
  • Your life will be less stressful. A large amount of homework is one of the key reasons why so many kids are worried. It is sometimes necessary to step away from the mountain of papers and assignments and take a deep breath. In this instance, you will require online python assistance.

How Do You Select the Right Service?

You should now begin your search for the greatest homework assistance provider.

Here are the top five tips for finding a good provider that can be trusted with your assignment:

  • Check out some reviews. There are numerous websites that review various services and provide genuine user feedback. You should look at those to see if the service you’ve chosen is worth a shot.
  • Examine the feedback from customers. What do customers say about the service on its website? What about websites that publish customer reviews? Compare the two to see if a service can be trusted.
  • Don’t be afraid to ask questions. When ordering anything online, it is acceptable to ask questions. There are a plethora of websites available on the internet, making it difficult to select one. However, because there is such a vast range of them, it is perfectly OK to ask anything and choose the service that is truthful with you.
  • Rates should be compared. It is now time to look at the costs that these services have to offer. Because prices might vary, you must first decide how much you are willing to pay. Keep in mind that the ultimate pricing is frequently determined by the deadline.
  • Talk with the service about your assignment. Remember to include all necessary assignment information. Speak with assistance if necessary to determine the deadline and other criteria. If you want to get good grades, you must be able to articulate your wants and desires.

Seek the Help You Need with Your Assignments

So, what are your thoughts on online homework assistance? Have you resolved whether or not to use it? Remember that these are only useful tools, not complete answers. However, if you use such services correctly, you will be able to reach whatever goals or aspirations you have in mind. There is no need for you to be stressed all the time, so consider getting python homework help if you want to make the most of your time in college or school. Remember, there is no shame in asking for help.

 

 

Python Assignment Help: Can You Put Your Trust in Someone to Handle Your Python Assignment? Read More »

Python fork() – Creating child processes Using the fork() Method

Python’s fork() method allows us to create child processes from the processes through which it was called.

System Call:

To gain access to the kernel mode, a system call is used. It is a method for a program to communicate with the operating system and request its services to do specific tasks.

As a result, all system calls are executed in the kernel (privileged) mode, and after the execution is finished, control is returned to the user mode. In shortened form, a system call is also known as syscall.

There are two modes of operation in modern computer systems: user mode and kernel mode.

All user programs and processes run in User mode and have no direct access to the kernel mode. This is done to protect the operating system against alterations or modifications induced by any user program.

If a user program needs to execute privileged tasks, it must rely on the operating system for assistance, which it can only obtain through system calls. And it is the system calls that, via API, deliver the different services of the operating system to user programs and processes (Application Program Interface).

fork() Method in Python:

There are numerous system calls for managing the various sorts of services offered by the operating system. Furthermore, these varies depending on the operating system.

System calls are divided into five major categories:

  • System calls relating to files
  • System calls relating to devices
  • System calls related to the process
  • System calls related to information
  • System calls related to communication

Build a child process and show the process ids of both the parent and child processes.

Fork system call uses for to establish a new process called child process that runs concurrently with process (whose process called system call fork) and is named parent process. Following the creation of a new child process, both processes will execute the next instruction following the fork() system call.

OS Module

The OS module in Python allows you to use operating system dependent functionality.  The OS module’s functions allow users to interface with the underlying operating system that Python is running on, whether it’s Windows, Mac, or Linux.

It is imported as shown below:

import os

Working of fork() Method

The following are the main characteristics of the fork() method/statement:

  • When called from within a program, it accepts no arguments.
  • If the child process is successfully created, both the parent and child processes will execute the next statement/instruction, which will be followed by the fork() statement.
  • The number of child processes equals 2N – 1, where N is the number of fork() statements used within the main program.

When the Python fork() instruction is executed, it returns three types of integer values:

Zero(0): If the child process is successfully created, a value of zero (0) is returned to it.
positive(+ve): If the child process is successfully created, a positive (+ve) value is returned to the parent process. This positive value is usually the PID of the newly formed child process, which is the **process ID.
negative(-ve): If an error occurs during the creation of the child process for any reason, a negative (-ve) value is returned to the parent process.

Process ID, often known as PID, is a unique identifier assigned with each process present inside the computer. The process ID of any process can be retrieved by another system call called getpid(), which is an example of an information-related system call. The getpid() command returns the process ID of the calling process.

Inside the program, it can be called as shown below:

os.fork()

System Calls:

fork(): fork() is an operation that allows a process to generate a replica(copy) of itself. It is typically a system call that is implemented in the kernel.
getpid(): The process ID (PID) of the calling process is returned by getpid().

Child processes creation using the fork():

Example1:

Approach:

  • Import os module using the import keyword.
  • Call the fork() method 3 times to create the child processes.
  • Print some random text.
  •  It is executed by both the parent and child processes.
  • Since the fork() method is called 3 times it is executed 8 times in total (7+1).
  • 2^3 -1 = 7 times by child processes
  • 1 time by the parent process.
  • The Exit of the Program.

Below is the implementation:

# Import os module using the import keyword.
import os

# Call the fork() method to create the child processes
os.fork()
os.fork()
os.fork()

# Print some random text.
# It is executed by both the parent and child processes.
# Since the fork() method is called 3 times it is executed 8 times in total(7+1)
# 2^3 -1 = 7 times by child processes
# 1 time by parent process
print("welcome to Python-programs")

Output:

welcome to Python-programs 
welcome to Python-programs 
welcome to Python-programs 
welcome to Python-programs 
welcome to Python-programs 
welcome to Python-programs 
welcome to Python-programs 
welcome to Python-programs

Example2:

Approach:

  • Import os module using the import keyword.
  • Call the fork() method to create the child processes.
  • Check if the value returned by the fork() method is greater than 0 using the if conditional statement.
  • If it is true, then print “It is a parent process” with the PID.
  • Get the PID using the getpid() method.
  • Else, print “It is a child process” with the PID.
  • Get the PID of the child process using the getpid() method.
  • The Exit of the Program.

Below is the implementation:

# Import os module using the import keyword.
import os
# Call the fork() method to create the child processes
rslt_valu = os.fork()
# Check if the value returned by the fork() method is greater than 0 using the
# if conditional statement.
if rslt_valu > 0:
    # If it is true, then print "It is a parent process" with the pid.
    # Get the PID using the getpid() method
    p_id = os.getpid()
    print("This is a Parent process with the pid = ", p_id)
else:
    # Else, print "It is a child process" with the pid.
    # Get the PID of the child process using the getpid() method
  p_id = os.getpid()
  print("This is a child process with the pid = ", p_id)

Output:

This is a Parent process with the pid = 60
This is a child process with the pid = 264

 

 

Python fork() – Creating child processes Using the fork() Method Read More »

Python Program for Setting a Variable Value to Infinity

Your dataset cannot be represented by a single number? In Python, how about setting your variable value to infinity? That’s exactly what we’re going to speak about today!

We frequently need to initialize a variable in Python with a large positive or large negative value. When comparing variables to determine the minimum or maximum in a set, this is fairly common.

In Python, positive infinity is considered the largest positive value, whereas negative infinity is considered the largest negative value.

Python, representation of infinity as an integer:
The concept of portraying the infinite as an integer contradicts the definition of infinity. In any programming language as of 2020, there is no mechanism to represent infinity as an integer. Float values, on the other hand, can be used to represent an infinite integer in Python because it is a dynamic language. To represent infinity, use float(‘inf’) as an integer.

The following is a list of Python infinite representations.

1)Using float variables to initialize with infinity:

Float is the most simple approach to set a variable to positive or negative infinity without utilizing any modules.

Since infinity can be both positive and negative, it can be expressed as a float(‘inf’) and a float(‘-inf’) respectively.

For Example:

Approach:

  • Pass ‘inf’ as an argument to the float() function to define a positive infinite integer and store it in a variable.
  • Print the positive Infinity.
  • Pass ‘-inf’ as an argument to the float() function to define a negative infinite integer and store it in another variable.
  • Print the negative Infinity.
  • The Exit of the Program.

Below is the implementation:

# Pass 'inf' as an argument to the float() function to define a positive
# infinite integer and store it in a variable
pos_infnty = float('inf')
# Print the positive Infinity
print('The result of positive Infinity = ', pos_infnty)

# Pass '-inf' as an argument to the float() function to define a negative
# infinite integer and store it in another variable
neg_infnty = float('-inf')
#  Print the negative Infinity
print('The result of negative Infinity = ', neg_infnty)

Output:

The result of positive Infinity =  inf
The result of negative Infinity =  -inf

Using Math module:

The math module in Python can also be used to generate infinite integers.

Approach:

  • Import math module using the import keyword.
  • Get the positive Infinity value by using the math.inf and store it in a variable.
  • Print the positive Infinity.
  • Get the negative Infinity value by using the -math.inf and store it in another variable.
  • Print the negative Infinity.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Get the  positive Infinity value by using the math.inf and store it in a variable
pos_infnty = math.inf
# Print the positive Infinity
print('The result of positive Infinity = ', pos_infnty)

# Get the negative Infinity value by using the -math.inf and store it in another
# variable
neg_infnty = -math.inf
# Print the negative Infinity
print('The result of negative Infinity = ', neg_infnty)

Output:

The result of positive Infinity =  inf
The result of negative Infinity =  -inf

By using the decimal module in Python

The decimal module in Python can also be used to generate endless float values.
It is written as Decimal(‘Infinity’) for a positive infinite value and Decimal(‘-Infinity’) for a negative infinite value.

Approach:

  • Import Decimal function from the decimal module using the import keyword.
  • Pass ‘Infinity’ as an argument to the Decimal() function to define a positive infinite integer and store it in a variable.
  • Print the positive Infinity.
  • Pass ‘-Infinity’ as an argument to the Decimal() function to define a negative infinite integer and store it in another variable.
  • Print the negative Infinity.
  • The Exit of the Program.

Below is the implementation:

# Import Decimal function from decimal module using the import keyword.
from decimal import Decimal
# Pass 'Infinity' as an argument to the Decimal() function to define a positive
# infinite integer and store it in a variable
pos_infnty = Decimal('Infinity')
# Print the positive Infinity
print('The result of positive Infinity = ', pos_infnty)

# Pass '-Infinity' as an argument to the Decimal() function to define a negative
# infinite integer and store it in another variable
neg_infnty = Decimal('-Infinity')
#  Print the negative Infinity
print('The result of negative Infinity = ', neg_infnty)

Output:

The result of positive Infinity =  Infinity
The result of negative Infinity =  -Infinity

By using the Numpy library in Python

The Numpy module in Python can also be used to represent infinite values. It is denoted as np.inf for positive infinite value and -np.inf for negative infinite value.

Approach:

  • Import numpy library as np using the import keyword.
  • Get the positive Infinity value by using the np.inf and store it in a variable.
  • Print the positive Infinity.
  • Get the negative Infinity value by using the -np.inf and store it in another variable.
  • Print the negative Infinity.
  • The Exit of the Program.

Below is the implementation:

# Import numpy library as np using the import keyword.
import numpy as np
# Get the  positive Infinity value by using the np.inf and store it in a variable
pos_infnty = np.inf
# Print the positive Infinity
print('The result of positive Infinity = ', pos_infnty)

# Get the negative Infinity value by using the -np.inf and store it in another
# variable
neg_infnty = -np.inf
# Print the negative Infinity
print('The result of negative Infinity = ', neg_infnty)

Output:

The result of positive Infinity = inf 
The result of negative Infinity = -inf

Python Checking to See if a Number Is Infinite

To determine whether a given integer is infinite or not, use the math library’s isinf() method, which returns a boolean result.

Approach:

  • Import math module using the import keyword.
  • Get the positive Infinity value by using the math.inf and store it in a variable.
  • Print the positive Infinity.
  • Get the negative Infinity value by using the -math.inf and store it in another variable.
  • Print the negative Infinity.
  • Check whether the above-obtained results are infinite or not using the isinf() function and print the result.
  • Give some random number as static input and store it in another variable.
  • Check whether the given number is infinite or not using the isinf() function and print the result.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Get the  positive Infinity value by using the math.inf and store it in a variable
pos_infnty = math.inf
# Print the positive Infinity
print('The result of positive Infinity = ', pos_infnty)

# Get the negative Infinity value by using the -math.inf and store it in another
# variable
neg_infnty = -math.inf
# Print the negative Infinity
print('The result of negative Infinity = ', neg_infnty)
# Check whether the above obtained results are infinite or not using the
# isinf() function and print the result.
print(math.isinf(pos_infnty))
print(math.isinf(neg_infnty))
# Give some random number as static input and store it in another variable
gvn_numb = 1000
# Check whether the given number is infinite or not using the isinf() function and
# print the result.
print(math.isinf(gvn_numb))

Output:

The result of positive Infinity =  inf
The result of negative Infinity =  -inf
True
True
False

Python Arithmetic Operations on Infinity

Adding or removing a value to or from infinity has no effect.

import math
pos_infnty = math.inf
neg_infnty = -math.inf
# Arithmetic operations
# Adding or removing a value to or from infinity has no effect.
rslt = pos_infnty + 500
print(rslt)
rslt = neg_infnty + 700
print(rslt)

rslt = pos_infnty - 500
print(rslt)
rslt = neg_infnty - 700
print(rslt)

Output:

inf
-inf
inf
-inf

Arithmetic operations involving two infinities

import math
pos_infnty = math.inf
neg_infnty = -math.inf
# Arithmetic operations involving two infinities
# Addition
rslt = pos_infnty + neg_infnty
print("Addition of positive and negative infinities = ", rslt)

# Multiplication
rslt = pos_infnty * neg_infnty
print("Multiplication of positive and negative infinities = ", rslt)

# Division
rslt = pos_infnty / neg_infnty
print("Division of positive and negative infinities = ", rslt)

Output:

Addition of positive and negative infinities =  nan
Multiplication of positive and negative infinities =  -inf
Division of positive and negative infinities =  nan

Python Program for Setting a Variable Value to Infinity Read More »

Python’s Top 11 Real-World Applications

We live in a digital world that is entirely governed by lines of code. Every business, from healthcare to the military to finance to research, relies on software to perform properly. We have a long list of programming languages that help in software development. Python is one of these, and it has emerged as the most profitable and exciting programming language. According to a poll, more than 80% of developers choose Python as their primary coding language. The primary reason for this is its enormous libraries and frameworks, which power the process.

Python supports multi-platform operating systems, making it significantly easier to create and implement applications. DropBox, Instagram, and other well-known services are examples.

Top 11 Real-World Applications of Python

  • Web Development
  • Game Development
  • Machine Learning(MI) and Artificial Intelligence(AI)
  • Audio and Visual Applications
  • Desktop GUI Applications
  • Software Development
  • Business Applications
  • Scientific and mathematical Applications
  • DataScience
  • Education programs and training courses
  • Language Development

Web Development

It is one of Python’s most amazing applications. This is because Python includes a number of frameworks such as Django, Flask, Bottle, and many others that make development easier. Furthermore, Python includes built-in modules and tools that make web programming a breeze.

Python for web development additionally provides:

  • Incredible visualization
  • Developmental convenience
  • improved security
  • Rapid development process

Python frameworks are well-known for their security, dependability, and flexibility.
These web frameworks make operations like content management, data administration, communication, and linking to Internet procedures like HTTP, SMTP, XML, FTP, POP, and JSON easier.

Game Development

Python comes with lots of handy extensions that are perfect for building interactive games.
For example, PyGame and PySoy, a 3D game engine that supports Python 3, are two Python-based libraries that are widely used in game creation.
Python serves as the basis for notable games such as Battlefield 2, World of Tanks, Vega Strike, and Civilization IV.
Aside from game production, the game creator can utilize Python to create systems that will simplify numerous specialized operations such as level design, etc.

Aside from game production, game designers can use Python to create tools that facilitate specific processes such as level design or dialogue tree construction, and even utilize those tools to export those activities in formats that the core game engine can use. Many game engines also employ Python as a programming language.

Machine Learning(MI) and Artificial Intelligence(AI)

AI and machine learning models and projects are fundamentally distinct from traditional software models. When discussing AI/ML projects, the tools and technology used, as well as the skill set necessary, are vastly different from those used in the development of traditional software projects. AI/ML applications necessitate a language that is robust, secure, and versatile, as well as one that is supplied with tools capable of handling the different particular requirements of such projects.

Python possesses all of these characteristics, and as a result, it has become one of the most popular languages among Data Science practitioners, and Python is a required tool in data science classes.

Python’s simplicity, consistency, platform freedom, rich library collection, and active community make it the ideal choice for developing AI and ML applications. The following are some of the best Python packages for AI and ML:

  • SciPy – for advanced computing
  • Pandas is a data analysis tool that can be used for a variety of purposes.
  • Seaborn is used for data visualization.
  • Keras, TensorFlow, and Scikit-learn are ML frameworks.
  • NumPy is a Python library for high-performance scientific computation and data processing.
  • Aside from these libraries, other Python-based libraries useful for AI and ML projects include NLTK, Caffee, PyTorch, and Accord.NET.

Audio and Visual Applications

Python’s audio and video applications are without a doubt its most spectacular feature. Python comes with a variety of tools and libraries to help you do your assignment flawlessly. Python-coded applications include well-known ones such as Netflix, Spotify, and YouTube. This is something that libraries like the given below can handle.

  • Dejavu
  • OpenCV
  • Pyo
  • Mingus
  • SciPy

Python is used to create apps that can interact with multimedia. Python Libraries are used to create video and audio apps such as TimPlayer and Cplay.

They dominate other media players in terms of stability and performance.
A few examples of multimedia libraries are Gstreamer, Pyglet, and QT Phonon.

Desktop GUI Applications

Python is used to create desktop apps. It includes the Tkinter library, which can be used to create user interfaces. Other helpful toolkits include wxWidgets, Kivy, and PYQT, which can be used to create programs for a variety of platforms.

Python not only has an English-like syntax, but it also has a modular architecture and can run on many operating systems. Python is a fantastic choice for designing desktop-based GUI applications because of these features, as well as its powerful text processing facilities.

Software Development

Python is an excellent choice for software development. Python is used by well-known apps such as Google, Netflix, and Reddit. This language has great features such as:

  1. Independent of the platform
  2. Built-in libraries and frameworks make development easier.
  3. Improved code reuse and readability
  4. A high degree of compatibility
  5. Aside from this, Python has expanded capabilities for working with fast-evolving technologies such as machine learning and artificial intelligence. Because of all of these embedded features, it is a popular choice for software development.

This is why Python is used as a support language by software developers to handle development, testing, and management.

Business Applications

Business Apps differ from our standard applications in that they include domains such as e-commerce, ERP, and many more. They require applications that are scalable, expandable, and easily understandable, and Python meets all of these requirements.

To create such commercial apps, platforms such as Tryton are available.

The entire development process grows complex as the business applications are developed while taking into account the unique requirements of the organization’s operational model. Python can make a major difference in this situation.

Odoo is business management software that offers an automated solution for your business processes.

Scientific and mathematical Applications

Python’s huge library base has made it a helpful resource in computer science.
Python includes a number of scientific and mathematical libraries that make it easy to solve a wide range of challenging problems.

Python, in reality, serves as the foundation for programs that deal with computation and scientific data processing. Python is used to create applications such as FreeCAD (3D modeling software) and Abaqus (finite element technique software).

Some of the most prominent Python frameworks/packages for scientific and numerical applications are listed below:

  • SciPy – Scientific numeric library
  • pandas – library for data analytics
  • Numpy – basic numerical package
  • IPython – command shell
  • Natural Language Toolkit – Library of mathematical and textual analysis

DataScience

Data is like money, If you know how to extract useful information from data, you can take calculated risks and increase profits. You examine the data you have, execute operations, and extract the necessary information. Pandas and NumPy libraries can assist you in extracting information.

You may also view data libraries like Matplotlib and Seaborn, which are useful for plotting graphs and much more. Python provides you with the tools you need to become a Data Scientist.

Data science includes data collecting, sorting, analysis, and visualization. Python has incredible functionality for dealing with statistics and sophisticated mathematical calculations. Data science workers benefit from the existence of built-in libraries. TensorFlow, Pandas, and Socket learning are three prominent libraries that help with the data science process. These packages provide a framework for fine-tuning data models, preparing data, and performing complicated data analysis.

Education programs and training courses

  • To begin with, if there is any programming language, it is Python.
  • Python’s easy learning curve and simplicity are two of the main reasons why it is one of the most extensively utilized languages in education programs at both the primary and secondary levels.
  • Python has a very simple syntax that is similar to the English language.
  • Python, on the other hand, is not simply a fantastic beginner language; professional developers and coders all around the world rely significantly on Python.

Language Development

Python design and module development has been the driving force behind the development of various programming languages over the years, including Boo, Swift, Coffee-Script, Cobra, and OCaml.
For reasons such as object model, syntax, and indentation, all of these languages have numerous commonalities with Python.

 

 

 

 

Python’s Top 11 Real-World Applications Read More »

Python Program for Membership and Identity Operators

Python provides a number of operators for performing manipulation and operations on data values and variables on a larger scale.

Let us see the two important types of Python operators:

  • Membership Operators
  • Identity Operators

Membership Operators (‘in’, ‘not in’)

Membership operators are used to validate a value’s membership. It checks for membership in a sequence, such as strings, lists, or tuples.

This means that it checks for the presence of the given data sequence in another sequence or structure and validates it.

‘in’ – Membership operator:

The ‘in’ operator is used to determine whether or not a value exists in a sequence. If it finds a variable in the given sequence, it returns true; otherwise, it returns false.

For Example:

Approach:

  • Give the first list as static input and store it in a variable.
  • Give the second list as static input and store it in another variable.
  • Iterate in the given first list using the for loop and ‘in’ Operator.
  • Inside the for loop, Check if the element present in the first list is also present in the second list using the if conditional statement and ‘in’ Operator.
  • If it is true, then print the respective element of the first list.
  • The Exit of the Program.

Below is the implementation:

# Give the first list as static input and store it in a variable.
gvn_fstlst = [4, 7, 1, 15, 2]
# Give the second list as static input and store it in another variable.
gvn_scndlst = [7, 6, 2, 5]
# Iterate in the given first list using the for loop and 'in' Operator
for numb in gvn_fstlst:
    # Check if the element present in the first list is also present in the
    # second list using the if conditional statement and 'in' Operator.
    if numb in gvn_scndlst:
        # If it is true, then print the respective element of the first list.
        print(numb, "is common in both the lists")

Output:

7 is common in both the lists
2 is common in both the lists

‘not in’ – Membership operator:

If the ‘not in’ operator does not encounter a given data value in a sequence such as a list, string, etc., it returns True.

For Example:

Approach:

  • Give the list as static input and store it in a variable.
  • Give the number as static input and store it in another variable.
  • Check if the given number is not present in the given list using the if conditional statement and ‘not in’ Operator.
  • If it is true, then print the respective element of the first list.
  • If it is true, then print “The given number is NOT present in the given list”.
  • Else print “The given number is present in the given list”.
  • The Exit of the Program.

Below is the implementation:

# Give the list as static input and store it in a variable.
gvn_lst = [4, 7, 1, 15, 2]
# Give the number as static input and store it in another variable.
gvn_numb = 15
# Check if the given number is not present in the given list using the
# if conditional statement and 'not in' Operator.
if gvn_numb not in gvn_lst:
    # If it is true, then print "The given number is NOT present in the given list"
    print("The given number", gvn_numb, "is NOT present in the given list")
else:
    # Else print "The given number is present in given the list"
    print("The given number", gvn_numb, "is present in the given list")

Output:

The given number 15 is present in the given list

Identity Operators (‘is’, ‘is not’)

The Identity operators in Python allow us to check the equivalence of values in terms of what memory location they are pointing to, have the same data type as expected, and so on.

‘is’ – Identity operator:

If the variables on either side of the operator point to the same object, the result is true; otherwise, the result is false.

For Example:

Approach:

  • Give the number as static input and store it in a variable.
  • Check if the datatype of the given number is a float value using the if conditional statement and ‘is’ identity Operator.
  • If it is true, then print “The given number is a floating-point number”.
  • Else print “The given number is NOT a floating-point number”.
  • The Exit of the Program.

Below is the implementation:

# Give the number as static input and store it in another variable.
gvn_numb = 15.25
# Check if the type of the given number is a float value using the
# if conditional statement and 'is' identity Operator.
if type(gvn_numb) is float:
    # If it is true, then print "The given number is a floating-point number"
    print("The given number", gvn_numb, "is a floating-point number")
else:
    # Else print "The given number is NOT a floating-point number"
    print("The given number", gvn_numb, "is NOT a floating-point number")

Output:

The given number 15.25 is a floating-point number

‘is not’ – Identity operator:

If the variables on either side of the operator point to the same object, the result is false; otherwise, the result is true.

For Example:

Approach:

  • Give the number as static input and store it in a variable.
  • Check if the datatype of the given number is not a float value using the if conditional statement and ‘is not’ identity Operator.
  • If it is true, then print “The given number is NOT a floating-point number”
  • Else print “The given number is a floating-point number”
  • The Exit of the Program.

Below is the implementation:

# Give the number as static input and store it in another variable.
gvn_numb = 10
# Check if the type of the given number is not a float value using the
# if conditional statement and 'is not' identity Operator.
if type(gvn_numb) is not float:
    # If it is true, then print "The given number is NOT a floating-point number"
    print("The given number", gvn_numb, "is NOT a floating-point number")
else:
    # Else print "The given number is a floating-point number"
    print("The given number", gvn_numb, "is a floating-point number")

Output:

The given number 10 is NOT a floating-point number

 

Python Program for Membership and Identity Operators Read More »

Python Faker Module with Examples

Faker Module:

The Faker module is used to produce random data, including attributes such as name, age, and location.

The question now is, why would one require Fake data? We may require false or fake data to either fill in the blanks in the databases with artificial data or to just test an algorithm.

How to import the Faker module?

To examine the various functions and methods of the faker library, we must first import it.

Installation

pip install faker

Output:

Collecting faker Downloading Faker-10.0.0-py3-none-any.whl (1.2 MB) 
|████████████████████████████████| 1.2 MB 2.1 MB/s Requirement already 
satisfied: python-dateutil>=2.4 in /usr/local/lib/python3.7/dist-packages 
(from faker) (2.8.2) Requirement already satisfied: typing-extensions>=
3.10.0.2 in /usr/local/lib/python3.7/dist-packages (from faker) (3.10.0.2)
Requirement already satisfied: text-unidecode==1.3 in /usr/local/lib/
python3.7/dist-packages (from faker) (1.3) Requirement already satisfied:
six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=
2.4->faker) (1.15.0)
Installing collected packages:
faker Successfully installed faker-10.0.0

Importing

from faker import Faker

How to Create Fake data?

To generate some Fake data, we must first create a  faker object of the  Faker library and then apply various functions to the object to generate the false random data.

Use the faker.name() function to generate a random name.

Approach:

  • Import faker from Faker module using the import keyword.
  • Create an object for the Faker library and store it in a variable.
  • Generate a random name using faker_obj.name() function and print it.
  • The Exit of the Program.

Below is the implementation:

# Import faker from Faker module using the import keyword.
from faker import Faker
# Create an object for the Faker library and store it in a variable.
faker_obj = Faker()
# Generate a random name using faker_obj.name() function and print it
print(faker_obj.name())

Output:

Tammy Clay

Program to generate 8 random names:

# Import faker from Faker module using the import keyword.
from faker import Faker
# Create an object for the Faker library and store it in a variable.
faker_obj = Faker()
# Generate 8 random names using faker_obj.name() function, for loop and print it
for itr in range(8):
    print(faker_obj.name())

Output:

Bryan Hernandez 
Christopher Perez 
Phillip Freeman 
Edward Mills 
Larry Russell 
Denise Benjamin 
Mary Reeves 
Jesus Washington

How to Create Fake data in different languages?

By declaring it in the Faker object, we may easily generate fake data in multiple languages.

Approach:

  • Import faker from Faker module using the import keyword.
  • Create an object for the Faker library by passing some random language and store it in a variable.
  • Generate 8 random names(in hindi) using faker_obj.name() function, for loop and print it.
  • The Exit of the Program.

Below is the implementation:

# Import faker from Faker module using the import keyword.
from faker import Faker
# Create an object for the Faker library by passing some random
# language as an argument to it and store it in a variable.
faker_obj = Faker('hi_IN')
# Generate 8 random names using faker_obj.name() function, for loop and print it.
for itr in range(8):
    print(faker_obj.name())

Output:

सिंह, रतन
विवेक सेनाधीश 
मोहिनी नाम 
शान्ता बालासुब्रमणियम 
अद्विका मदन 
दीया रामशर्मा 
हेगडे, मोहिनी
शनाया मंडल

Generation of Faker Text

Use the text() function, to generate fake text and sentences with the same faker objects

Approach:

  • Import faker from Faker module using the import keyword.
  • Create an object for the Faker library and store it in a variable.
  • Generate fake text using the text() function with the faker object and print it.
  • The Exit of the Program.

Below is the implementation:

# Import faker from Faker module using the import keyword.
from faker import Faker
# Create an object for the Faker library and store it in a variable.
faker_obj = Faker()
# Generate fake text using the text() function with the faker object and print it.
print(faker_obj.text())

Output:

Citizen spend wear reach customer science. Charge sell instead from certain. Increase work free teacher partner weight.

Generation of Fake Tabular data

Let’s now try to generate a large number of data points in Python using the dataframes of pandas library. We use the profile() method of the faker object to collect various or multiple types of data.

# Import pandas library as pd using the import keyword.
import pandas as pd
# Import faker from Faker module using the import keyword.
from faker import Faker
# Create an object for the Faker library and store it in a variable.
faker_obj = Faker()
# Use profile() method of the faker object to collect various or multiple
# types of data.
# Store it in another variable.
rslt_data = [faker_obj.profile() for a in range(5)]
# Generate some random tabular data using the DataFrame() function
# of pandas library
# Store it in another variable.
tab_data = pd.DataFrame(rslt_data)
# Print the tabular fake data
print(tab_data)

Output:

                           job  ...   birthdate
0  Research scientist (medical)  ...  1924-01-28
1                Therapist, art  ...  1908-02-22
2                  Tour manager  ...  1932-08-31
3   Careers information officer  ...  1995-06-03
4         Nutritional therapist  ...  2015-02-20

[5 rows x 13 columns]

 

 

Python Faker Module with Examples Read More »