How to Code in Python 3 Lisa Tagliaferri download
How to Code in Python 3 Lisa Tagliaferri download
download
https://ebookmeta.com/product/how-to-code-in-python-3-lisa-
tagliaferri/
https://ebookmeta.com/product/mastering-python-for-
bioinformatics-how-to-write-flexible-documented-tested-python-
code-for-research-computing-1st-edition-ken-youens-clark/
https://ebookmeta.com/product/coffee-break-python-50-workouts-to-
kickstart-your-rapid-code-understanding-in-python-1st-edition-
mayer-christian/
https://ebookmeta.com/product/coffee-break-python-50-workouts-to-
kickstart-your-rapid-code-understanding-in-python-1st-edition-
mayer-christian-2/
https://ebookmeta.com/product/taming-the-messiah-the-formation-
of-an-ottoman-political-public-sphere-1600-1700-1st-edition-
aslihan-gurbuzel/
Frontiers of Data and Knowledge Management for
Convergence of ICT, Healthcare, and Telecommunication
Services (EAI/Springer Innovations in Communication and
Computing) Suman Paul (Editor)
https://ebookmeta.com/product/frontiers-of-data-and-knowledge-
management-for-convergence-of-ict-healthcare-and-
telecommunication-services-eai-springer-innovations-in-
communication-and-computing-suman-paul-editor/
https://ebookmeta.com/product/her-daddy-s-jewel-mc-daddies-
book-5-1st-edition-laylah-roberts/
https://ebookmeta.com/product/data-for-all-1st-edition-john-k-
thompson-2/
https://ebookmeta.com/product/with-gentleness-and-respect-
pauline-and-petrine-studies-in-honor-of-troy-w-martin-biblical-
tools-and-studies-1st-edition-eric-f-mason-editor/
https://ebookmeta.com/product/choreographing-discourses-a-mark-
franko-reader-1st-edition-mark-franko-alessandra-nicifero-
editor-2/
Histology A Text and Atlas With Correlated Cell and
Molecular Biology 8th Edition Pawlina Md Faaa
https://ebookmeta.com/product/histology-a-text-and-atlas-with-
correlated-cell-and-molecular-biology-8th-edition-pawlina-md-
faaa/
How To Code in Python 3
Lisa Tagliaferri
1. Introduction
2. Python 2 vs Python 3: Practical Considerations
3. How To Install Python 3 and Set Up a Local Programming
Environment on Ubuntu 16.04
4. How To Install Python 3 and Set Up a Local Programming
Environment on macOS
5. How To Install Python 3 and Set Up a Local Programming
Environment on Windows 10
6. How To Install Python 3 and Set Up a Local Programming
Environment on CentOS 7
7. How To Install Python 3 and Set Up a Programming
Environment on an Ubuntu 16.04 Server
8. How To Write Your First Python 3 Program
9. How To Work with the Python Interactive Console
10. How To Write Comments
11. Understanding Data Types
12. An Introduction to Working with Strings
13. How To Format Text
14. An Introduction to String Functions
15. How To Index and Slice Strings
16. How To Convert Data Types
17. How To Use Variables
18. How To Use String Formatters
19. How To Do Math with Operators
20. Built-in Python 3 Functions for Working with Numbers
21. Understanding Boolean Logic
22. Understanding Lists
23. How To Use List Methods
24. Understanding List Comprehensions
25. Understanding Tuples
26. Understanding Dictionaries
27. How To Import Modules
28. How To Write Modules
29. How To Write Conditional Statements
30. How To Construct While Loops
31. How To Construct For Loops
32. How To Use Break, Continue, and Pass Statements when
Working with Loops
33. How To Define Functions
34. How To Use *args and **kwargs
35. How To Construct Classes and Define Objects
36. Understanding Class and Instance Variables
37. Understanding Inheritance
38. How To Apply Polymorphism to Classes
39. How To Use the Python Debugger
40. How To Debug Python with an Interactive Console
41. How To Use Logging
42. How To Port Python 2 Code to Python 3
Introduction
Why Learn To Code
Software and technology are becoming increasingly integrated into our
everyday lives, allowing us to accomplish tasks, navigate to destinations,
make purchases, and stay connected with friends. Because of how pervasive
software now is to the human experience, it is important for all of us to
learn some of the key foundational elements of computer programming.
While some may choose to study computer science as part of their formal
education, everyone can benefit from an understanding of algorithmic
thinking and computational processes. Learning how the software that we
use on a daily basis is made can allow us as end users to evaluate how and
why these applications are developed, enabling us to think critically about
these tools and how to improve them.
Just like any other product, computer programs are designed and
developed by people who have unconscious biases, make errors, and may
not be considering all aspects of a problem they are trying to solve. Though
development teams may do thorough testing and work to create
sophisticated and useful programs, they do not always meet the needs and
expectations of all users. While not everyone needs to learn to code
complex programs, learning how coding works can help shape the future of
technology and increase the number of stakeholders, decision makers, and
knowledge producers who can work to build better software for everyone.
Some of us may choose to solve challenging problems within the
technology sector, but for those of us not working in computer science, a
programming background can still be a great asset to our professional
fields. Computer programming provides many applications across domains,
and can help us solve problems in specialities such as medicine, economics,
sociology, history, and literature, to name a few. By integrating technology’s
methodologies into our own fields, we can leverage computational logic
and software design and development practices in our work. When we
synthesize knowledge across spheres and collaborate with people from
different backgrounds, we can innovate in new, more inclusive ways that
can enact meaningful impact across many communities.
Why Learn Python
Extremely versatile and popular among developers, Python is a good
general-purpose language that can be used in a variety of applications. For
those with an understanding of English, Python is a very human-readable
programming language, allowing for quick comprehension. Because Python
supports multiple styles including scripting and object-oriented
programming, it is considered to be a multi-paradigm language that enables
programmers to use the most suitable style to complete a project.
Increasingly used in industry, Python offers a lot of potential for those who
would like to begin coding while also being a good choice for those looking
to pick up an additional programming language.
Learning the key concepts of Python can help you understand how
programs work while also imparting foundational logic that can serve you
in other domains. Understanding what Python and computer programming
can offer you both as a user and as a developer is important as technology is
further integrated into daily life.
As you work through this book, you will be able to increase your
awareness of computer programming, improve your logical thinking, and
eventually become a producer of software. Being able to create software
that runs is a very rewarding endeavor, and can help you serve those around
you by increasing their access and empowering them to become
collaborators. The more communities involved in the creation of software
development, the more communities there will be whose needs are served
by software.
How To Use This Book
This book is designed to be used in a way that makes sense for you. While
it is arranged to ramp up an emerging developer, do not be constrained by
the order: feel free to move throughout the book in a way that makes sense
for you. Once you are familiar with the concepts, you can continue to use
the book as a source of reference.
If you use the book in the order it is laid out, you’ll begin your
exploration in Python by understanding the key differences between Python
3 and the previous versions of the language. From there, you’ll set up a
programming environment for your relevant local or server-based system,
and begin by learning general Python code structure, syntax, and data types.
Along the way, you’ll gain a solid grounding in computational logic within
Python, which can help you learn other programming languages. While the
beginning of the book focuses on scripting in Python, the end of the book
will take you through object-oriented coding in Python, which can make
your code more modular, flexible, and complex without repetition. By the
end of the book, you’ll learn how to debug your Python code and finally
how to port Python code across versions.
When you are done with the book, we encourage you to look at project-
based tutorials to put your knowledge into play while creating projects that
can help you solve problems. While you are working on these projects, you
can continue to refer to the chapters in this book as reference material.
As part of your learning process and once you feel comfortable, we
recommend that you contribute to an open-source project to improve
programs and drive greater access via software and technical documentation
pull requests or repository maintenance. Our community is bigger than just
us and building software together can make sure that everyone has an
opportunity to participate in the technology we use every day.
Python 2 vs Python 3: Practical
Considerations
Python 2
Python 3
"I thought, of course, that you would hear me when I called, but you
didn't seem to come into that room at all."
"We did go there," said Kathleen; "but you know there is no place to
hide there but the cupboard, and that had been left wide open by Rupert
when he hid there at the beginning of the game. So we just ran up the stairs,
put our heads in and saw that the room and cupboard were empty, and then
ran off to what we thought were more likely places."
"Then that's why I did not hear your footsteps. The wood must be
fearfully thick. I lay still till I began to feel suffocated, and then I tried to
get out. I tried and tried, I pushed with my hands, then I lay on my back and
pressed with my knees and kicked with my feet. It wasn't a bit of good, I
only hurt myself and got more choky. Then my nose began to bleed, and I
gave up trying, and lay with my face to the side of the chest. Oh, it was
horrible, auntie! I thought that I should die; and I wondered how long you
would be before you found me, and what poor father and mother would say
when they heard about it."
"There, there, don't pile it on," said Jack, rubbing his hand across his
eyes; "tell us how you got out, that's what we want to know. Anyone could
get in and be choked; but it's a regular Maskelyne and Cooke's dodge to get
out again instead."
"I can't tell you, I don't remember anything till I woke up in bed in a
strange room. I know now it was Robert's. Your new man gave me a
sandwich and something out of a little bottle, and I——"
"My new man?" repeated father, with his eyes wide open. "Why, I
haven't one in the place that has been here less than five years."
"Oh! perhaps I made a mistake," said Harold, rather wearily; "I didn't
know his face, so I thought he must be a stranger. He had a white coat on
like a coachman, and——"
"Hurrah!" cried Jack, "my mysterious stranger went to the rescue. Could
he talk English, Harold? Was he very furious?"
"He was very kind; but he didn't speak once, I remember. He bathed my
face with water out of Robert's basin, and I noticed that he kept looking out
of the window. Then I heard a noise like a bell; and he went to the window,
stood there a minute, then he waved his hand to me, and unlocked the door
and went."
"The moon shone right in at the window. I don't know who the man was,
if uncle says he was not one of the servants; but I'm very tired, and don't
want to talk any more."
So we all were; but I am afraid if there had been any one sleeping in my
little room I should have talked all night about our mysterious stranger.
The next morning things went on much as usual, till Kathleen and
Rupert came to carry me upstairs. Then you would have laughed if you
could have heard all the wild guesses we made as to the identity of our
strange visitor.
"Let's have a good look at that chest," said Rupert, when Kathleen had
declared she had done with it for the present.
"Your heels made a very queer sound in it last night, Rupert," I said.
"Only for pity's sake let somebody sit on the edge of it whilst it is open. I
don't want you to be guillotined or smothered."
Harold perched himself in such a manner that the lid could not possibly
fall, and dangled his legs against the side. It was a wonderful old chest, and
we have it still in our house. It is made of black oak, is just five feet long,
and about two feet wide.
"I know," said Rupert, presently, springing out of the box. "Where's the
foot rule?"
"What's the joke now?" said Harold. "Are you going to measure it to see
if there's room for the mysterious stranger to hide in?"
"If it rattles," said Jack, sagaciously, "there isn't much inside. But let's
see if we can open it."
They pushed and knocked in turns, but it was useless; they only grew
tired and cross.
"Get along, you stupid old thing," said Harold, losing patience; "I'm sick
of you." As he spoke he sprang from his perch and administered a kick to
the obstinate box. Kathleen was holding the lid on the opposite side, and
saw the bottom of the box move.
It did not spring up, it merely stood just enough away from the box for
Rupert to put his fingers under it and lift it out bodily. A low groan of
disappointment escaped us all. They had pulled my chair close to the chest,
and I was able to look into it as well, and certainly shared in the groan. I
can't say what we had expected. It may have been gold, it may have been
treasures of another kind. Most certainly we none of us had expected to see
a few packets of papers, yellow with age, and covered with dust.
So engrossed had we been that we had not noticed a step in the room;
and when Rupert raised himself from the chest with a bundle of papers in
his hand, declaring he would take them to uncle, my blood seemed to stand
still and my heart almost to jump into my mouth when a voice, with a
strong French accent, said—
By the side of my couch, almost touching me, stood the man whom we
had named Jack's Ghost!
CHAPTER XI.
A Day of Surprises.
"Are you better, now?" said the stranger, laying his hand on Harold's
shoulder.
"Yes, thank you," replied Harold, jerking himself away, while Rupert
gave expression to what we all felt and thought.
"I wish you'd go about like other people, instead of sneaking up the sides
of walls." As he spoke he went to the window. "Uncle George!" he shouted
at the top of his voice. An answer came from a distance. "Make haste up
here, there's a man who wants to see you."
"I pity him if he is in your den," father called out merrily, after about two
minutes during which time we had all been perfectly silent, Kathleen and
Harold keeping a strict guard over the chest by sitting on it.
The mysterious stranger took his hat from his head, and father gazed at
him for one brief second, then held out both his hands.
"FATHER GAZED AT HIM FOR ONE SECOND, THEN HELD OUT
BOTH HIS HANDS."
"Yes, I, George."
The words meant little enough, but the tone spoke volumes, and, to our
terrible distress, the stranger dropped on the oak chest and was convulsed
with sobs.
"Right about face, quick march," whispered Jack, hopping off as well as
he could. "Look after the baggage."
"No, it isn't. He will have to let me. I feel like the poultry in the farmer's
yard, who declared 'twas hard that their nerves should be shaken, and their
rest be marred by the visit of Mr. Ghost. Oh, I'll go to Brighton, if uncle
likes; but pass the rest of my days in the tower-room, I won't."
A burst of laughter restored Jack's good temper, and then we all went
into the dining-room and told mother about everything. I'm a good deal
older now than I was then, but I have not yet got out of the way of wanting
to rush off to tell mother everything. Happy are the youngsters who have
such a mother as I have, and who try all their lives never to do or say
anything that they would be afraid or ashamed to tell her. Let me see, I said
"rush off," did I not? and I meant it; though at the time I am speaking about,
I was dependent on other people's rushing instead of my own.
Mother was nearly as excited as we were about the stranger, only she
seemed to know a little more about him.
"Your father had a half-brother named Joseph," she said; "his mother
was a Frenchwoman, and when she died her little boy was sent by your
grandfather to stay with her relations in France."
"There was some unhappiness about him, dear, and you know your
father never speaks about anything like that. He bears it all, and says
nothing. Take care, Edric! what are you going to do?"
Slowly and carefully I drew my legs round, and then, leaning on her
arm, with Rupert on the other side of me I put them to the ground. Of
course, it was but a poor attempt at walking, but still, it was an attempt, and
mother seemed utterly amazed. Nothing ever happens just as one has
expected and planned it; I had so often gone through that little scene in my
mind, and yet I had not the least intention of acting it that day.
"Well done, my darling, well done! How came you to think of trying
that? Why, you will walk as well as I do some day."
"I know, mother," I said, colouring, for I was ashamed of myself now;
"but in those days I did not really feel as if I cared to move about. I would
rather not walk at all than be hurt as that woman hurt me. Now, Kathleen is
different; she has not hurt me once, and yet she would not let me off a
minute before the half-hour."
"Mary! Mary!" said father's voice, "I want you for a moment." He
pushed the door open and stood transfixed.
"Do you know, laddie," he said, seriously. "I have found out that there is
one thing in this world which always brings a reward, and that is
unselfishness. It's your mother that's unselfish, not I. If it had not been for
her, I should never have consented to have your cousins here. I hated the
thought of it, and only consented to please her. Wow see the reward we
have got, far beyond what I, at least, deserve; my little helpless laddie is
going to try to be like other children, and my half-brother is restored to his
inheritance. Come and see him, Mary; I'll tell you all about it presently,
children."
CHAPTER XII.
The Lost Will
"So we shall dine here, then," said Rupert, with a look at Jack, who had
fixed himself in an armchair in a most determined attitude; "unless you
prefer going up to the tower-room."
"Never again," said Jack, gravely; "uncle says we've done him good, and
when he comes back I mean to ask for our reward. 'Tis a very good den that
we live in, to laugh, or to talk, or to play in; but to hide or to think, or to be
quite alone, 'tis the very worst den that ever was known."
"Bravo, Jack! poor old Hudibras wouldn't know his own lines if he were
here. Give us some more of that sort of thing to make the time pass till
uncle comes home. I'm just burning with curiosity."
It seemed a long day in spite of all the fun we managed to get in one way
or another; but "be the day weary, be the day long, at length it ringeth to
evensong," and about seven o'clock we heard the horse's feet in the yard,
and my parents came in alone. Even then we had, of course, to wait a short
time before they were ready to tell us what we were longing to hear.
"Now I'll tell you all about the mysterious stranger," said father, at last.
"But I am tired, and you must not interrupt me. You will have plenty of time
to ask questions another day. It is just fifteen years since my half-brother
Joe was in this room. His mother died when he was about three years old,
and at her request your grandfather sent the little fellow over to Normandy
to be brought up by his mother's brother. This brother was a very rich man,
and when my father married again he offered to adopt Joe, bring him up as
his own son, and leave him all he possessed, if my father would consent. He
would not, however, do this, and insisted on Joe returning home at once, so
one of my first recollections is being carried about by my big brother Joe.
As I got older I used to spend most of my days in the tower-room, where
Joe was always busy with some carpentering, or work of one kind or
another. Your grandfather was a severe man, very harsh in his management
of children, and Joe often resented what he considered his unkindness. That
oak chest, which was nearly the cause of your death the other night, Harold,
was the cause of our separation. One day the French count came to stay
with our father, and Joe, who was really very fond of him, owing to having
spent his early years with him, wanted to go back with him; but our father
would not consent. Joe tells me now that he distinctly heard the Frenchman
say, 'Well, I've made my will in his favour, and I shall leave it with you. I've
made you executor, and when I am dead you will let the boy come over to
Normandy. It's a pity you won't let him go back with me, for there are
people who would like to oust him out of his property if they could.'
"Years passed away, and one day, when Joe had been imprisoned in the
tower-room for some naughtiness, he ran away, climbing down by those
very steps that he climbed up yesterday, and which he had made when quite
a youngster, to be able to get in or out of his play-room as he liked. I said
your grandfather was a harsh man; and when he heard of Joe's flight, he
knew of course he had gone to Normandy, and he made a solemn vow that
Joe should never enter the house again. I was about twelve then, and old
enough to see that, however harsh my father might be, he really loved his
elder son. He was never the same again, and one morning we found him
struck by paralysis. He recovered consciousness before he died, and seemed
anxious to tell us something, but he could neither write nor speak distinctly,
though I fancy he wanted to say something about Joe. My mother and I
lived alone here, writing occasionally to Normandy, but never expecting to
see Joe again. One day, fifteen years ago, I was sitting writing, when a
servant came to say that a stranger had called, and had pushed past her,
saying he wanted to go to the tower-room. Running upstairs quickly, I
found your Uncle Joe kneeling at the oak chest, which stood open. I was
angry at his impertinence, and seizing him by the collar as he knelt, I shook
him violently and reproached him with killing our father, and then coming
into the house in that fashion. He was pale with anger; but he is a noble
character, in spite of all his faults. He remembered that we were brothers,
and would not strike me. 'I came to see if I could find the Count D'Arcy's
will,' he said; 'a cousin of his claims the estate, and I have nothing to prove
that he made me his heir. I know the Count gave it to our father.' 'And I
know that our father forbade you to enter the house while he was alive. I
shall not allow it now he is dead. Go!' I replied, pointing to the door. He
went, and I have never seen him till to-day."
"What has he been doing all these years?" I asked, unable to restrain my
curiosity any longer.
"He has been working hard and making a name for himself at Rouen,
while the Count's cousin has been squandering the estate. From time to
time, he tells me, he has come over to England, stayed at the Watermill,
with the old woman who nursed him as a baby, and made occasional visits
to the tower-room in search of the will which was to restore him to his
rights, going and coming always by means of those steps."
"Whatever made him think of that place?" said Jack, finding that my
interruption was unreproved.
"He says that he remembered your grandfather telling some one that
there was a false bottom in the oak chest which made a splendid hiding-
place. He had tried several times to get it open, but he had never succeeded.
The last time he tried was on that evening when he heard from old Jane that
we had gone to Colchester. When he opened the lid of the chest he found
Harold inside quite unconscious and almost suffocated. Of course, he knew
the ways of the house; so he carried him to the coachman's room, where he
stayed with him till the gong sounded for prayers."
"Then they were his footmarks we saw in the mud," cried Rupert. "What
a joke. Don't you tell him I said they were nineteens. What is he like? Is he
very cross?"
"Here he comes, so you can judge for yourselves," said mother, opening
the door to admit our new-found uncle, who turned out to be just as jolly as
any boys could wish.
*****
Years passed by. Uncle Joe, by means of the will, which was hidden in
the oak chest, came into possession of a beautiful little estate in Normandy,
where we all spent many happy days with our French cousins, for he had
married a Frenchwoman. I say we, because, thanks to my cousins' good
influence on mind and body, I became as strong as any one could expect,
and was able to enjoy school life in a quiet way, though never fit for rough
games, and always rather sensitive about the slight hump on my back.
Never shall I forget my grief when those first holidays were over, and
father and mother and I stood at the door to wave our farewells.
"God bless you, children," said father; "you've done us all good."
"Then you don't wish the savages had never come, uncle," shouted Jack,
with a merry smile.
"No, no, no!" replied father; and then the carriage went out of sight,
though the sounds of the Australian "cooee" reached us for some minutes
afterwards.
THE END.
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.