Articles

Develop your own virtual assistant using python - part 2

Develop your own virtual assistant using python - part 2


This is the part-2 of virtual assistant in python. Click the link for part -1 of virtual assistant program in python.

 

Now in this article, we will move forward and discuss more modules that we are going to use in our virtual assistant in python.

 

So let's start off,

 

🗓Datetime module in python: 

In the Python programming language, to work with date and time we need a module known as the Datetime module in python.

 

This module is built-in in python we did not have to install this module.DateTime module is used to supply the classes in the program. These classes help us to use a large number of functions related to date, time, etc in our program.

To use datetime module in python in our program and print the present date and time, simply use the below lines of code in our program:

 

import datetime
present = datetime.datetime.now()
print(present)

Output of this code is shown below:

 

2021-05-12 15:40:42.474106

It prints the current date in the yy/mm/day format and the current time of your time zone. This serves as simple datetime module in python example.

 

📙Options available with the datetime module:

Datetime module has several options to take the information from the date object. some of these methods are shown below:

🧐strftime() method in python:

This method helps us to convert the datetime object into several string methods for processing.

 

To use strftime method in python method we have to import the datetime class from the datetime module.

strftime example python 3: To get the year data from the datetime printed output use the below lines of code in your program.

 

from datetime import datetime
present = datetime.now() # present date and time
print(present) # full output of datetime class
year = now.strftime("%Y") # to separate year data from the full output of datetime class
print("year:", year)

Output of these lines of code is shown below:

 

2021-05-12 18:20:51.536835
year: 2021

To print the weekday using datetime module use the following lines of code given below:

 

import datetime
present=datetime.datetime.now()
print(present.strftime("%A"))

Thats all about module Datetime.In the next article we will discuss more modules we are going to use in our virtual assistant.

 

So stay tuned for next article. Hope you are liking this series of articles. Meet you in next article.


Basic Python Programs
Python Conversion Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Ayush Bajpai
I am a data science enthusiast. I love to learn new technology 🛠🛠.you can reach me at this url www.linkedin.com/in/ayushbajpai47
Page Views :    Published Date : Jun 01,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!