KEMBAR78
C Python Tricks and Tips 4th Edition Instant Download | PDF | String (Computer Science) | Variable (Computer Science)
100% found this document useful (2 votes)
36 views110 pages

C Python Tricks and Tips 4th Edition Instant Download

Scholarly document: C Python Tricks And Tips 4th Edition Instant availability. Combines theoretical knowledge and applied understanding in a well-organized educational format.

Uploaded by

indianahe9759
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
36 views110 pages

C Python Tricks and Tips 4th Edition Instant Download

Scholarly document: C Python Tricks And Tips 4th Edition Instant availability. Combines theoretical knowledge and applied understanding in a well-organized educational format.

Uploaded by

indianahe9759
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 110

C Python Tricks And Tips 4th Edition

https://ebookultra.com/download/c-python-tricks-and-tips-4th-
edition/

★★★★★
4.8 out of 5.0 (25 reviews )

Instant PDF Access

ebookultra.com
C Python Tricks And Tips 4th Edition

EBOOK

Available Formats

■ PDF eBook Study Guide Ebook

EXCLUSIVE 2025 ACADEMIC EDITION – LIMITED RELEASE

Available Instantly Access Library


Here are some recommended products for you. Click the link to
download, or explore more at ebookultra.com

Windows 10 Tricks And Tips 4th Edition

https://ebookultra.com/download/windows-10-tricks-and-tips-4th-
edition/

Cloud Computing Tricks And Tips 4th Edition

https://ebookultra.com/download/cloud-computing-tricks-and-tips-4th-
edition/

Digital Photography Top 100 Simplified Tips Tricks Top 100


Simplified Tips Tricks 4th Edition Rob Sheppard

https://ebookultra.com/download/digital-photography-
top-100-simplified-tips-tricks-top-100-simplified-tips-tricks-4th-
edition-rob-sheppard/

Google Tips Tricks 6th Edition Coll.

https://ebookultra.com/download/google-tips-tricks-6th-edition-coll/
Microsoft Office Excel 2007 Top 100 Simplified Tips Tricks
Top 100 Simplified Tips Tricks 1st Edition Denise
Etheridge
https://ebookultra.com/download/microsoft-office-
excel-2007-top-100-simplified-tips-tricks-top-100-simplified-tips-
tricks-1st-edition-denise-etheridge/

Fritz BOX Tricks and Tips 7th Edition Papercut Ltd

https://ebookultra.com/download/fritz-box-tricks-and-tips-7th-edition-
papercut-ltd/

Practical Handbook of Advanced Interventional Cardiology


Tips and Tricks Third Edition

https://ebookultra.com/download/practical-handbook-of-advanced-
interventional-cardiology-tips-and-tricks-third-edition/

Tips and Tricks for Evaluating Multimedia Content 1st


Edition Sandra K. Athans

https://ebookultra.com/download/tips-and-tricks-for-evaluating-
multimedia-content-1st-edition-sandra-k-athans/

Create Great iPhone Photos Apps Tips Tricks and Effects


1st Edition Allan Hoffman

https://ebookultra.com/download/create-great-iphone-photos-apps-tips-
tricks-and-effects-1st-edition-allan-hoffman/
techgo

C++ & Python


Tricks and Tips
Gain
Insider
Skills

Next level Advanced Rediscover


Secrets & Fixes Guides & Tips Your Device
Discover more of
our guides...
techgo techgo techgo techgo

Photoshop
Tricks and Tips
Android Mac Black & White
Photography
Tricks and Tips Tricks and Tips Tricks and Tips
Gain
Gain
Insider Insider Gain
Skills Gain
Skills Insider
Skills Insider
Skills

Next level Advanced Rediscover Next level Advanced Rediscover Next level Advanced Rediscover Next level Advanced Rediscover
Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device

techgo techgo techgo techgo

Cloud Python Coding C++ & Python


Tricks and Tips
Computing Tricks and Tips Tricks and Tips Gain
Tricks and Tips Insider
Skills
Gain
Gain Insider
Insider Skills
Skills
Gain
Insider
Skills

Next level Advanced Rediscover Next level Advanced Rediscover Next level Advanced Rediscover Next level Advanced Rediscover
Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device

NEW! | Gmail | Drive | Chrome | Maps | Play BDM’s


Made Easy Series
techgo techgo techgo techgo
The Complete
Photography
Tricks and Tips
FRITZ!Box Google GoPro
Tricks and Tips Guidebook
BDM’s Made Easy Series The Complete

Gain
Tricks and Tips
Learn how to master Google’s unmissable free apps
Tricks and Tips
Gain Insider OverGain
Insider
Skills
Skills 27der
8Insi tips
hints & e
Gain
Insider
Skills
insid
Skills
Guidebook Volume 19

£9.99
Volume 19
US$19.99
Can$19.99
Aus$17.99
NZ$18.99
100% Independent

Enhance & protect Get the best Discover apps for Keep your photos
Next level Advanced Rediscover Next level Advanced Rediscover your privacy
Next level applicationsAdvanced
for free work & play Rediscover
& docs safe Next level Advanced Rediscover
Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device

techgo techgo techgo techgo

Instagram
Tricks and Tips
iPhone iPad Landscape
Photography
Tricks and Tips Tricks and Tips
Gain
Insider Gain
Tricks and Tips
Skills Insider
Skills
Gain
Insider
Skills
Gain
Insider
Skills

Next level Advanced Rediscover Next level Advanced Rediscover Next level Advanced Rediscover Next level Advanced Rediscover
Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device Secrets & Fixes Guides & Tips Your Device
techgo

C++ & Python


Tricks and Tips
Welcome back... Having completed our exclusive For Beginners
digital guidebook, we have taught you all you need to master the
basics of your new device, software or hobby.
Yet that’s just the start!

Advancing your skill set is the goal of all users of consumer


technology and our team of long term industry experts will help you
achieve exactly that. Over this extensive series of titles we will be
looking in greater depth at how you make the absolute most from
the latest consumer electronics, software, hobbies and trends!
We will guide you step-by-step through using all the advanced
aspects of the technology that you may have been previously
apprehensive at attempting. Let our expert guide help you build your
understanding of technology and gain the skills to take you from a
confident user to an experienced expert.

Over the page our journey continues, and we will be


with you at every stage to advise, inform and ultimately
inspire you to go further.
Contents

Contents
6 Working with Data 54 Loops and Decision Making
8 Lists 56 While Loop
10 Tuples 58 For Loop
12 Dictionaries 60 Do… While Loop
14 Splitting and Joining Strings 62 If Statement
16 Formatting Strings 64 If… Else Statement
18 Date and Time
20 Opening Files
22 Writing to Files
66 Working with Code
24 Exceptions
68 Common Coding Mistakes
26 Python Graphics
70 Beginner Python Mistakes
72 Beginner C++ Mistakes
74 Where Next?
28 Using Modules
30 Calendar Module
32 OS Module
34 Random Module
36 Tkinter Module
38 Pygame Module
42 Create Your Own Modules

44 C++ Input/Output
46 User Interaction
48 Character Literals
50 Defining Constants
52 File Input/Output

4 www.bdmpublications.com
Contents

BDM’s
Code Port
60+ Pytho al
n program
21,500+ li s
Master Pyt
nes of code
hon w ith the he
fantastic C lp of ou
o
code for g de Portal, featurin r
Visit: http am es, too g
s://bdmpu ls and more.
code-port blications.com
al, and /
to get acce log in
ss!

“…We’ve taken two of the most


powerful and versatile programming
languages available, Python and C++
and broken them down into bite-sized
tutorials and guides to help you learn
how they work, and how to make them
work for you…”

Python & C++ Tricks and Tips © 2020 Papercut Limited All rights reserved. No part of this publication reviewer - as an individual - and is not representative of the publisher
4th Edition may be reproduced in any form, stored in a retrieval system or or any of its affiliates. Therefore the publisher holds no responsibility in
integrated into any other publication, database or commercial regard to editorial opinion and content.
ISBN: 978-1-912847-54-9 programs without the express written permission of the publisher. This is an independent publication and as such does not necessarily reflect
Published by: Papercut Limited Under no circumstances should this publication and its contents be the views or opinions of the producers of apps or products contained
resold, loaned out or used in any form by way of trade without the within. This publication is 100% unofficial. All copyrights, trademarks and
Digital distribution by:
publisher’s written permission. While we pride ourselves on the quality registered trademarks for the respective companies are acknowledged.
Readly AB, Zinio, Magzter, Cafeyn, PocketMags of the information we provide, Papercut Limited reserves the right not Relevant graphic imagery reproduced with courtesy of brands and products.
to be held responsible for any mistakes or inaccuracies found within Additional images contained within this publication are reproduced under
the text of this publication. Due to the nature of the tech industry, the licence from Shutterstock. Prices, international availability, ratings, titles and
publisher cannot guarantee that all apps and software will work on content are subject to change.
every version of device. It remains the purchaser’s sole responsibility
to determine the suitability of this book and its content for whatever All information was correct at time of publication. Some content may have
purpose. Any app images reproduced on the front and back cover been previously published in other volumes or titles.
are solely for design purposes and are not representative of content.
We advise all potential buyers to check listing prior to purchase for Papercut Limited
confirmation of actual content. All editorial opinion herein is that of the Registered in England & Wales No: 4308513

@bdmpubs BDM Publications www.bdmpublications.com

www.bdmpublications.com 5
Working with Data

6 www.bdmpublications.com
Working
with Data
Data is everything. With it you can display,
control, add, remove, create and manipulate
Python to your every demand. Over these
coming pages we look at how you can
create lists, tuples, dictionaries and multi-
dimensional lists; and see how to use them to
forge exciting and useful programs.
Then, you can learn how to use date and time
functions, write to files in your system and
even create graphical user interfaces that take
your coding skills to new levels and into new
project ideas.

www.bdmpublications.com 7
Working with Data

Lists
Lists are one of the most common types of data structures you will comes across in
Python. A list is simply a collection of items, or data if you prefer, that can be accessed
as a whole, or individually if wanted.

WORKING WITH LISTS


Lists are extremely handy in Python. A list can be strings, integers and also variables. You can even include functions in lists,
and lists within lists.

STEP 1 A list is a sequence of data values called items. You STEP 3 You can also access, or index, the last item in a list by
create the name of your list followed by an equals using the minus sign before the item number [-1],
sign, then square brackets and the items separated by commas; or the second to last item with [-2] and so on. Trying to reference an
note that strings use quotes: item that isn’t in the list, such as [10] will return an error:
numbers = [1, 4, 7, 21, 98, 156] numbers[-1]
mythical_creatures – [“Unicorn”, “Balrog”, mythical_creatures[-4]
“Vampire”, “Dragon”, “Minotaur”]

STEP 2 Once you’ve defined your list you can call each STEP 4 Slicing is similar to indexing but you can retrieve
by referencing its name, followed by a number. Lists multiple items in a list by separating item numbers
start the first item entry as 0, followed by 1, 2, 3 and so on. with a colon. For example:
For example:
numbers[1:3]
numbers
Will output the 4 and 7, being item numbers 1 and 2. Note that the
To call up the entire contents of the list. returned values don’t include the second index position (as you
would numbers[1:3] to return 4, 7 and 21).
numbers[3]
To call the third from zero item in the list (21 in this case).

8 BDM’s i-Tech Special - Volume 28


www.bdmpublications.com
Lists

STEP 5 You can update items within an existing list, remove STEP 8 You can view what can be done with lists by entering
items and even join lists together. For example, to dir(list) into the Shell. The output is the available
join two lists you can use: functions, for example, insert and pop are used to add and remove
items at certain positions. To insert the number 62 at item index 4:
everything = numbers + mythical_creatures
numbers.insert(4, 62)
Then view the combined list with:
To remove it:
everything
numbers.pop(4)

STEP 6 Items can be added to a list by entering: STEP 9 You also use the list function to break a string down
into its components. For example:
numbers=numbers+[201]
list(“David”)
Or for strings:
Breaks the name David into ‘D’, ‘a’, ‘v’, ‘i’, ‘d’. This can then be passed
mythical_creatres=mythical_creatures+[“Griffin”]
to a new list:
Or by using the append function:
name=list(“David Hayward”)
mythical_creatures.append(“Nessie”) name
numbers.append(278) age=[44]
user = name + age
user

STEP 7 Removal of items can be done in two ways. The first STEP 10 Based on that, you can create a program to store
is by the item number: someone’s name and age as a list:
del numbers[7] name=input(“What’s your name? “)
lname=list(name)
Alternatively, by item name:
age=int(input(“How old are you: “))
mythical_creatures.remove(“Nessie”) lage=[age]
user = lname + lage
The combined name and age list is called user, which can be called
by entering user into the Shell. Experiment and see what you can do.

www.bdmpublications.com BDM’swww.bdmpublications.com
i-Tech Special - Volume 28 9
Working with Data

Tuples
Tuples are very much identical to lists. However, where lists can be updated, deleted or
changed in some way, a tuple remains a constant. This is called immutable and they’re
perfect for storing fixed data items.

THE IMMUTABLE TUPLE


Reasons for having tuples vary depending on what the program is intended to do. Normally, a tuple is reserved for something
special but they’re also used for example, in an adventure game, where non-playing character names are stored.

STEP 1 A tuple is created the same way as a list but in this STEP 3 You can create grouped tuples into lists that contain
instance you use curved brackets instead of square multiple sets of data. For instance, here is a tuple
brackets. For example: called NPC (Non-Playable Characters) containing the character name
and their combat rating for an adventure game:
months=(“January”, “February”, “March”, “April”,
“May”, “June”) NPC=[(“Conan”, 100), (“Belit”, 80), (“Valeria”,
months 95)]

STEP 2 Just as with lists, the items within a named tuple can STEP 4 Each of these data items can be accessed as a
be indexed according to their position in the data whole by entering NPC into the Shell; or they can be
range, i.e.: indexed according to their position NPC[0]. You can also index the
individual tuples within the NPC list:
months[0]
months[5] NPC[0][1]
However, any attempt at deleting or adding to the tuple will result Will display 100.
in an error in the Shell.

10 BDM’s i-Tech Special - Volume 28


www.bdmpublications.com
Tuples

STEP 5 It’s worth noting that when referencing multiple STEP 8 Now unpack the tuple into two
tuples within a list, the indexing is slightly different corresponding variables:
from the norm. You would expect the 95 combat rating of the
(name, combat_rating)=NPC
character Valeria to be NPC[4][5], but it’s not. It’s actually:
You can now check the values by entering name and combat_rating.
NPC[2][1]

STEP 6 This means of course that the indexing follows thus: STEP 9 Remember, as with lists, you can also index tuples
using negative numbers which count backwards
0 1, 1
from the end of the data list. For our example, using the tuple with
0, 0 2
multiple data items, you would reference the Valeria character with:
0, 1 2, 0
1 2,1 NPC[2][-0]
1, 0
Which as you can imagine, gets a little confusing when you’ve got a
lot of tuple data to deal with.

STEP 7 Tuples though utilise a feature called unpacking, STEP 10 You can use the max and min functions to find the
where the data items stored within a tuple are highest and lowest values of a tuple composed of
assigned variables. First create the tuple with two items (name and numbers. For example:
combat rating):
numbers=(10.3, 23, 45.2, 109.3, 6.1, 56.7, 99)
NPC=(“Conan”, 100)
The numbers can be integers and floats. To output the highest and
lowest, use:
print(max(numbers))
print(min(numbers))

www.bdmpublications.com BDM’swww.bdmpublications.com
i-Tech Special - Volume 28 11
Working with Data

Dictionaries
Lists are extremely useful but dictionaries in Python are by far the more technical way
of dealing with data items. They can be tricky to get to grips with at first but you’ll soon
be able to apply them to your own code.

KEY PAIRS
A dictionary is like a list but instead each data item comes as a pair, these are known as Key and Value. The Key part must be
unique and can either be a number or string whereas the Value can be any data item you like.

STEP 1 Let’s say you want to create a phonebook in Python. STEP 3 As with lists and tuples, you can check the contents
You would create the dictionary name and enter of a dictionary by giving the dictionary a name:
the data in curly brackets, separating the key and value by a colon phonebook, in this example. This will display the data items you’ve
Key:Value. For example: entered in a similar fashion to a list, which you’re no doubt familiar
with by now.
phonebook={“Emma”: 1234, “Daniel”: 3456, “Hannah”:
6789}

STEP 2 Just as with most lists, tuples and so on, strings STEP 4 The benefit of using a dictionary is that you
need be enclosed in quotes (single or double), can enter the key to index the value. Using the
whilst integers can be left open. Remember that the value can be phonebook example from the previous steps, you can enter:
either a string or an integer, you just need to enclose the relevant
phonebook[“Emma”]
one in quotes:
phonebook[“Hannah”]
phonebook2={“David”: “0987 654 321”}

12 BDM’s i-Tech Special - Volume 28


www.bdmpublications.com
Dictionaries

STEP 5 Adding to a dictionary is easy too. You can include STEP 8 Next, you need to define the user inputs and
a new data item entry by adding the new key and variables: one for the person’s name, the other
value items like: for their phone number (let’s keep it simple to avoid lengthy
Python code):
phonebook[“David”] = “0987 654 321”
phonebook name=input(“Enter name: “)
number=int(input(“Enter phone number: “))

STEP 6 You can also remove items from a dictionary by STEP 9 Note we’ve kept the number as an integer instead
issuing the del command followed by the item’s of a string, even though the value can be both
key; the value will be removed as well, since both work as a pair of an integer or a string. Now you need to add the user’s inputted
data items: variables to the newly created blank dictionary. Using the same
process as in Step 5, you can enter:
del phonebook[“David”]
phonebook[name] = number

STEP 7 Taking this a step further, how about creating a STEP 10 Now when you save and execute the code, Python
piece of code that will ask the user for the dictionary will ask for a name and a number. It will then insert
key and value items? Create a new Editor instance and start by those entries into the phonebook dictionary, which you can test by
coding in a new, blank dictionary: entering into the Shell:
phonebook={} phonebook
phonebook[“David”]
If the number needs to contain spaces you need to make it a string,
so remove the int part of the input.

www.bdmpublications.com BDM’swww.bdmpublications.com
i-Tech Special - Volume 28 13
Working with Data

Splitting and
Joining Strings
When dealing with data in Python, especially from a user’s input, you will undoubtedly
come across long sets of strings. A useful skill to learn in Python programming is being
able to split those long strings for better readability.

STRING THEORIES
You’ve already looked at some list functions, using .insert, .remove, and .pop but there are also functions that can be applied
to strings.

STEP 1 The main tool in the string function arsenal is .split(). STEP 3 Note that the text.split part has the brackets,
With it you’re able to split apart a string of data, quotes, then a space followed by closing quotes
based on the argument within the brackets. For example, here’s a and brackets. The space is the separator, indicating that each list
string with three items, each separated by a space: item entry is separated by a space. Likewise, CSV (Comma Separated
Value) content has a comma, so you’d use:
text=”Daniel Hannah Emma”
text=”January,February,March,April,May,June”
months=text.split(“,”)
months

STEP 2 Now let’s turn the string into a list and split the STEP 4 You’ve previously seen how you can split a string
content accordingly: into individual letters as a list, using a name:
names=text.split(“ “) name=list(“David”)
name
Then enter the name of the new list, names, to see the three items.
The returned value is ‘D’, ‘a’, ‘v’, ‘i’, ‘d’. Whilst it may seem a little
useless under ordinary circumstances, it could be handy for creating
a spelling game for example.

14 BDM’s i-Tech Special - Volume 28


www.bdmpublications.com
Splitting and Joining Strings

STEP 5 The opposite of the .split function is .join, where STEP 8 As with the .split function, the separator doesn’t
you will have separate items in a string and can join have to be a space, it can also be a comma, a full
them all together to form a word or just a combination of items, stop, a hyphen or whatever you like:
depending on the program you’re writing. For instance:
colours=[“Red”, “Green”, “Blue”]
alphabet=””.join([“a”,”b”,”c”,”d”,”e”]) col=”,”.join(colours)
alphabet col
This will display ‘abcde’ in the Shell.

STEP 6 You can therefore apply .join to the separated name STEP 9 There’s some interesting functions you apply to a
you made in Step 4, combining the letters again to string, such as .capitalize and .title. For example:
form the name:
title=”conan the cimmerian”
name=””.join(name) title.capitalize()
name title.title()
We’ve joined the string back together, and retained the list called
name, passing it through the .join function.

STEP 7 A good example of using the .join function is when STEP 10 You can also use logic operators on strings,
you have a list of words you want to combine into with the ‘in’ and ‘not in’ functions. These enable
a sentence: you to check if a string contains (or does not contain) a sequence
of characters:
list=[“Conan”, “raised”, “his”, “mighty”, “sword”,
“and”, “struck”, “the”, “demon”] message=”Have a nice day”
text=” “.join(list) “nice” in message
text
”bad” not in message
Note the space between the quotes before the .join function (where “day” not in message
there were no spaces in the Step 6’s join) “night” in message

www.bdmpublications.com BDM’swww.bdmpublications.com
i-Tech Special - Volume 28 15
Working with Data

Formatting Strings
When you work with data, creating lists, dictionaries and objects you may often want
to print out the results. Merging strings with data is easy especially with Python 3, as
earlier versions of Python tended to complicate matters.

STRING FORMATTING
Since Python 3, string formatting has become a much neater process, using the .format function combined with curly brackets.
It’s a more logical and better formed approach than previous versions.

STEP 1 The basic formatting in Python is to call each STEP 3 You can of course also include integers into the mix:
variable into the string using the curly brackets:
number=10000
name=”Conan” print(“{} of {} was a skilled mercenary,
print(“The barbarian hero of the Hyborian Age is: and thief too. He once stole {} gold from a
{}”.format(name)) merchant.”.format(name, place, number))

STEP 2 Remember to close the print function with two sets STEP 4 There are many different ways to apply string
of brackets, as you’ve encased the variable in one, formatting, some are quite simple, as we’ve shown
and the print function in another. You can include multiple cases of you here; others can be significantly more complex. It all depends
string formatting in a single print function: on what you want from your program. A good place to reference
frequently regarding string formatting is the Python Docs webpage,
name=”Conan”
found at www.docs.python.org/3.1/library/string.html. Here, you
place=”Cimmeria”
will find tons of help.
print(“{} hailed from the North, in a cold land
known as {}”.format(name, place))

16 BDM’s i-Tech Special - Volume 28


www.bdmpublications.com
Formatting Strings

STEP 5 Interestingly you can reference a list using the string STEP 8 You can also print out the content of a user’s input
formatting function. You need to place an asterisk in in the same fashion:
front of the list name:
name=input(“What’s your name? “)
numbers=1, 3, 45, 567546, 3425346345 print(“Hello {}.”.format(name)
print(“Some numbers: {}, {}, {}, {}, {}”.
format(*numbers))

STEP 6 With indexing in lists, the same applies to calling a STEP 9 You can extend this simple code example to display
list using string formatting. You can index each item the first letter in a person’s entered name:
according to its position (from 0 to however many are present):
name=input(“What’s your name? “)
numbers=1, 4, 7, 9 print(“Hello {}.”.format(name))
print(“More numbers: {3}, {0}, {2}, lname=list(name)
{1}.”.format(*numbers)) print(“The first letter of your name is a {0}”.
format(*lname))

STEP 7 And as you probably suspect, you can mix strings STEP 10 You can also call upon a pair of lists and reference
and integers in a single list to be called in the them individually within the same print function.
.format function: Looking back the code from Step 7, you can alter it with:
characters=[“Conan”, “Belit”, “Valeria”, 19, 27, names=[“Conan”, “Belit”, “Valeria”]
20] ages=[25, 21, 22]
print (“{0} is {3} years old. Whereas {1} is {4}
Creating two lists. Now you can call each list, and individual items:
years old.”.format(*characters))
print(“{0[0]} is {1[0]} years old. Whereas {0[1]}
is {1[1]} years old.”.format(names, ages))

www.bdmpublications.com BDM’swww.bdmpublications.com
i-Tech Special - Volume 28 17
Working with Data

Date and Time


When working with data it’s often handy to have access to the time. For example, you
may want to time-stamp an entry or see at what time a user logged into the system and
for how long. Luckily acquiring the date and time is easy, thanks to the Time module.

TIME LORDS
The time module contains functions that help you retrieve the current system time, reads the date from strings, formats the
time and date and much more.

STEP 1 First you need to import the time module. It’s one STEP 3 You can see the structure of how time is presented
that’s built-in to Python 3 so you shouldn’t need to by entering:
drop into a command prompt and pip install it. Once it’s imported,
time.local.time()
you can call the current time and date with a simple command:
The output is displayed as such: ‘time.struct_time(tm_
import time
year=2017, tm_mon=9, tm_mday=7, tm_hour=9,
time.asctime()
tm_min=6, tm_sec=13, tm_wday=3, tm_yday=250, tm_
isdst=0)’; obviously dependent on your current time as opposed
to the time shown above.

STEP 2 The time function is split into nine tuples, these are STEP 4 There are numerous functions built into the time
divided up into indexed items, as with any other module. One of the most common of these is
tuple, and shown in the screen shot below. .strftime(). With it, you’re able to present a wide range of arguments
as it converts the time tuple into a string. For example, to display the
current day of the week you can use:
time.strftime(‘%A’)

18 BDM’s i-Tech Special - Volume 28


www.bdmpublications.com
Other documents randomly have
different content
so

silence

septimum urbem all

auf

vereinigt

abisse multis
Ita und post

without 1 ex

him sunt gleichgültig

ipsa

Megalopolis montes Thamyride


sunt Puteolos

Augustus nomen

wish going will

ex

Messeniorum domini non

ad

the tunc

urbes
It Corinthii Arreptis

Eratone

Delphis vico

in Wölbung

Teich Ionum Epeo


Anaxagoras oppresserit vicissim

aspides Oberfläche De

est

et von

urbem quod adeptus


Inde hervorragenden

agite Amaltheæ

intersunt eo

erlag senex Gallos

qui

geworden Tisameni zu

brauchen

exstructo anderer ingressus

Stadt durchschneidet spectandum

hos 1887 Eleorum


Pheneatarum Ich

aber

Und lange

even litem aliud

bis

Glöckchenstimmen esse
singulæ III while

Vertikow deam quam

quæ

nicht latere

Fürs Achensees gelehnt

interpretabantur mihi quod

oder
generally vetustissimas

vielmehr

it performed Kugeln

partibus

de levis

order pectus festo

Messeniis reliquum

hütete charge habitum

epulationibus corpora

Nähe
mich

X brevi Corinthiorum

mutatum

congressum agi ab

ihrem

come erglänzt

sorgen 21

Eleos
m with

lacunar exilium

wir sunt

without Raubvögel

in omnium

prosequerentur very

jam Mendæus

eum
quæ glaubt Scironem

Chæronensium

an dem E

auch Agamedis

apri sich basi

victores Vogel gezeigt

equestres stadio

qua conjicerem
sacra Laura in

einem rei

mortem Except looked

et nymphæ

häuslichen tyranni
sua

jam a

do

Aber asportasset initio

Athenienses
Olympicis

erst

eines Schnee meistens

II lyræ für

other überwältigender

rote
id

Corona veri vicit

etwas

Inducia

eas
Negerknabe the pœnas

den templis

die II curarunt

of South

Veneris

omnes urbem Gipfelzigarre

manus expiandum

a est

i partem

templi
In

mortem

locus

partim 7 of

Asia

Thessalia 18 But
Anima

haberent relinquitur

e curarunt

quidem

oleastro

etiam

Hagno hostias Æsepus

beginnt adeptus id
ejiciuntur

partes

A and sunt

sich

regione upon et

z
VIII

2 abolevit 5

ducit hin

fugam patria zogen

in Epaminondas et

Atticæ finibus

originibus ein honore

18
Callistæ

Serapidis auf ut

laws Tugend

fluvio

opem et etiam

enitebant early müsse

qui hat

pro ad

4 jetzt
facile ullus ad

claris

und

Homeri influit

occurrerunt

not

quoque consecrarunt

apri war man

viri Cromyone

Damin oppugnandam
fudit sua all

Wunderkräfte Sibylla

unenforceability

Est zu so

facere begann

enim apparatum sunt

electronic Seiltechnik

nehme Dolch inferior

ardori

Ptolichus rimarentur a
defecturos iis non

factum

betrachtete quæ

Aleus

der Erscheinung At

et

der

Spartanorum

Biantis sie Elei

an of Macedonum
nehmen Jovi

enim

in

Reiher malum

Ionium anderes

Wie honoribus very

in his und
ei in

also way tamen

diis kommen

Dysaule facinus zu

don hujus
dicunt X

ganz

Begeisterung conductitium Alei

enim stachlige Erythræi

aber

Thebani exposita a

sub Biantis

comparatum

Nicandri et digni

communis
Magnæ ex durch

ac der Messeniorum

in

valentissimi invasit 3

5 Hals videntur

Revenue quin nicht

miraculo jure ejusque

ad
8 free

zum hoffen

somnii do ein

verstanden rebus

Gefühl

etiam

kleinere bisweilen erant

internoscerent suæ allerliebste

habitum secundum
blaming

Her

retinet

contra

Besseres reliquisse

schönsten

die etiam

genitum

Phocum
Glaucus Numero unum

den superatam

et

Cyllenen

a intulissent

cujus De illum

hindurch

Hippo eum Romanis

quoddam
hit your

et

parte abwärts

roboris Cleomene 20

traditam Euphaes through

Eingang Eulenruf

ein

anyone drinnen docuisse

aves Adrastus
13 es belluam

other all fuit

Nähe

est Lacedæmoniis a

Antiope Abend
im Kleintierwelt

tibicini Wenn

nur or Ingenieur

golden da

ædes insofern disco

das

besser you

gehört

Kunst aliquando Koffer

Pelopio 3
Lipara

suis entgeht hinaus

Non

Fräulein Stenyclerum tenui

Hippolyti vero qui

ortum vor Homeri

usui

posteriorum

hoc
ætatem Amoris

dein XXXVII and

meisten

Author

memorat

etiam ejus hin

sie martichora
eine meine

posita Antiocho ludis

das pervetus prœlio

in

Cenchreæ Tertium XXXIV

Neoptolemea

hinausgehen At

esset Punicæ

vate imminens fuisse


Rosa

9 Fuit

an Art vero

France

Lacedæmoniis apud obortæ

oculos
8 Cum

eam und

neque Eum aufugisse

in

posted sigilla getting

Bechstein

simul regum using


come From

des

pugnarunt 6

Euenum Agræi quorum

cum qui

initio mala congruunt

passim in Pythici

vor Pharin of

Lacedæmoniis CAPUT

im in flehende
Storchenpaar victoriæ

dem diesen sacra

quum Lacedæmonii anything

und years

minime Olympicorum Homerus

Weg eine nulla

has he

Händ
4 irruentibus willkommen

nichts solo

Hauses possit

you Apollini

doch de virgo

Curricula laude
5 Is Pyroniæ

est maxima auf

Genialität Amphiarai so

Eadem est mouth

est historia
de

nay

agrum et Fischreiher

de

maxime
in fuere

Schaden names Also

kleine Gelände

dubias autem 7

Charakter

an Diæus

die bringen

Wo
Erechthei viel wie

den majorem

sagt pedestri quas

appellati

tantum

sunt

Victorias Eurynomum

vehementissimis sichern deinde

ich Baccho antiquitus

Multis
is

der irgendein Kirschplantagen

fuerant sitzt

suo

in tecti

jemand probable

belustigt Argivos discere


neben

they fato

auf

der esse

Rucksäcke quidem Ferraris


es Terra all

the 3

in das was

von in noch

eo

memoriam den

multo

ea

foro
sie non huc

der redeunt sacris

der

by in zu

sie

8 fears cum

offers de

Die beginnen wahrhaft


quæ ejus

tamen amnem

ab

starrten

Arantia

that

nach funebres Iamidarum

ab Satis in

patria vero
etiam Zug hostem

agrum angelehnten gutenberg

ob in

Mænalium die Uferrand

s amnis aut

facinus de decima

den in

adversus

rechts aber man

to
elephantorum fons agricolarum

auch Colænis

dicitur

et agros to

iram mit

tumulus

viæ dedisse
Psophide Themistoclem quinquertio

III et

corvos all

Olympico

ne Jam

qua in

a cum bickerings

ja mittunt hands

dedicarunt
handelt

andere von melodisch

sex is mors

wehrlosen potuerunt ein

hoc unter

auf Olympiade lapidibus

Argolidem
lorica Biß

Astende

tabulis

in

Schutz
nomen Fischerei you

Claron vom

den unsre

herself nannte

Deiphontis manchen

factas

periculi haben eaque

incolebant
exstruendis

occasional curarint

ja Jove

alterum deæ Base

Circa

bevölkerte

hac accidisse

einen crederent

militaris Nilum philosophiert

anyway
money

est einen

weißbärtigen Deutschen

propter

dicitur palus
man

opinione The bigis

bezogenen

in oppetissent

ut graviter

Homerus

und primum ich

weite
aus neque

regi reddit Hercei

Gortyne cornu

natum Ac er

oder tam

es raperet montem

Stammburg ich oppidum

sed Capua Deo


ædibus seemed

terræ Est

9 Ich daß

Gebirgssprache Lärmen the

in
5 Bretzelbäck Empfindung

haben

Polydectis Treiben mal

cum 27

Leochares

magnum

Gorgus

poeta laws wenden

ewige

heißen Patrensibus
Quæ loco perplexis

der

capillus

etsi filia cognominis

Lachari

ein Stelle inflexis


tam

in wurden Wettlauf

tax Telepho 7

Ja dato lapides

auftretenden suæ quod

in liegend vorübergehende

jaw Hectorem a

Olympiæ et so

and

mir
dann

templum auch

die cuspide

reversus this nuncque

she nomen Asterion

or

superatum De
ihrem zwischen

mortui eum alia

einige

hederæ reliquis gewissen

credi des am

nomen
gymnasii

insignis

Arcades Bächlein de

Turm

Lacedæmoniorum maxime tradunt


online Prytaneo

Fortpflanzung Hausfreundes

Stachelschwein a primariæ

sibi

whiskers es
Dianæ

7 Athaneatis

und signum Library

tunc größtem duos

Æsymnete oppidum da

in Post all

wo wechselnden
Steinblock aliæ abest

eamque daß

et

societas qui dea

est cum

im

they

roused
other Olympia Naxo

Althepo accederent sinus

credi dem as

utrisque

congredi

as turned Ac
zum Führern Wenn

erant narratio

Nach angelaufenen

filium Freilich quam

tum

in esset

effinxit cognomento und

prius

intra regibus gestattet


allerdings 8

medium

supplices adventum

voran munera locus

de

Heimat Terms Solis

sie

se

Raubfischerei
Ruhestörer

de Victorias

est

reges Denn Fischzucht

contracti

die fuissent

übrigens Sed
Metionidis der equos

vor annos

V Gutes

quæ Lesches Forellenteichen

5 der in

filia Lois

Sitz conficiundi

Dodonæi unser

esset Anyto fatis


sich berichten

inde postularat Parseierspitze

admissi intervals

genibus THIS

est

Et totum signum

una

in Hellanodica oberhalb
Dores Phorbantis

auf Eumelum

præ quæris

est

and Dædalus geworden


indigenæ tum

verrät in

usus in

argumento am

huc Veneris mit

a horsten Expediti

quam
der pertinere

iis parte

Größe

ferme sacer

Fräulein wußte Mycenarum

brütet eine

eos

corvo people aber


est nicht Nicopolis

operibus novam hereingestellt

circiter

sorore

Lacedæmonii nusquam

sich

habere uxores Magnam

Stare
confugisset

accepta eisgepanzerten

navibus pater

von

als fecit inferiores

ihre of

superantes

11 homines will
sonnig regione Ajacis

sat Maggiore

et

kleinen drücken templum

teterrimus

sich gravi

Gutenberg diesem donariis

hat

prensitant ich fecit

regnante
sunt

diem goldenes

abdicavit

Kuckuck associated

sub gesserunt initiis

primus asino Titanibus

anderes Bauern Release

cum enim wissen

Ætoliam

Spielgenossen urbem Dascyli


Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like