Algorithms For Dummies


PART 1   Getting Started



Download 7,18 Mb.
Pdf ko'rish
bet161/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   157   158   159   160   161   162   163   164   ...   651
Bog'liq
Algorithms

 

   


  PART 1 

 Getting Started

Interacting with Dates

Dates and times are items that most people work with quite a bit. Society bases 

almost everything on the date and time that a task needs to be or was completed. 

We make appointments and plan events for specific dates and times. Most of our 

day revolves around the clock. When working with algorithms, the date or time at 

which a particular step in a sequence occurs can be just as important as how the 

step occurs and what happens as a result of performing the step. Algorithms rely 

on date and time to organize data so that humans can better understand the data 

and the resulting output of the algorithm.

Because of the time-oriented nature of humans, it’s a good idea to look at how 

Python deals with interacting with date and time (especially storing these values 

for later use). As with everything else, computers understand only numbers — 

date and time don’t really exist. The algorithm, not the computer, relies on date 

and time to help organize the series of steps performed to solve a problem.

To work with dates and times, you must issue a special 

import datetime

 com-

mand. Technically, this act is called importing a module. Don’t worry about how the 



command works right now — just use it whenever you want to do something with 

date and time.

Computers do have clocks inside them, but the clocks are for the humans using 

the computer. Yes, some software also depends on the clock, but again, the 

emphasis is on human needs rather than anything the computer might require. To 

get the current time, you can simply type datetime.datetime.now() and press 

Enter. You see the full date and time information as found on your computer’s 

clock, such as 

datetime.datetime(2016, 12, 20, 10, 37, 24, 460099)

.

You may have noticed that the date and time are a little hard to read in the existing 



format. Say that you want to get just the current date, and in a readable format. To 

accomplish this task, you access just the date portion of the output and convert it 

into a string. Type str(datetime.datetime.now().date()) and press Enter. You now 

have something a little more usable, such as 

'2016-12-20'

.

Interestingly enough, Python also has a 



time()

 command, which you can use to 

obtain the current time. You can obtain separate values for each of the components 

that make up date and time using the 

day



month



year


hour


minute


second


, and 

microsecond

 values. Later chapters help you understand how to use these various 

date and time features to make working with algorithms easier.




CHAPTER 4


Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   157   158   159   160   161   162   163   164   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish