Learn python 3 the hard way pdf download free






















In the introduction, Mr. Shaw makes a big deal about how if you, the reader, feel like he is insulting your intelligence, then you are not in the intended audience for this book. I assume he is attempting to be funny, but he comes across as snarky, at best. Regardless of whether you enjoy that type of writing, the core content is pretty good.

I think beginners will benefit from the book. Think Python free PDF download. Facebook 0 Tweet 0. Previous Article Skype now has a new feature that helps conduct technical and coding interviews. Next Article Which programming language should I spend time to? Search a tutorial Search for:. You will hit the first confusing thing which is everything at first and then stop. If you keep trying, keep typing it in, keep trying to understand it and reading about it, you will eventually get it.

If you go through this whole book, and you still do not understand how to code, at least you gave it a shot. You can be proud of that. It is simply the exercise you complete to get your computer to run Python. You should follow these instructions as exactly as possible. If you have problems following the written instructions, then watch the included videos for your platform.

You should do the exercises in Appendix A first before continuing with these exercises. Install it like you would any other software. If Atom does not suite you, then see Alternative Text Editors at the end of this exercise. Put Atom your text editor in your dock, so you can reach it easily. Find your Terminal program. Search for it. You will find it.

Put your Terminal in your dock as well. Run your Terminal program. In your Terminal program, run python3. Type quit , Enter, and get out of python3. You should be back at a prompt similar to what you had before you typed python.

If not, find out why. Learn how to make a directory in the Terminal. Learn how to change into a directory in the Terminal. Use your editor to create a file in this directory.

Go back to Terminal using just the keyboard to switch windows. Back in Terminal, list the directory with ls to see your newly created file. Your computer might be different but should be similar to this. You do not need to be the administrator to do this.

Both options are available during setup. Run PowerShell from the Start menu. Search for it, and you can just press Enter to run it. Run your PowerShell program which I will call Terminal later. Download Python 3. Be sure to check the box that says to add Python 3.

In your PowerShell Terminal program, run python. You run things in Terminal by just typing the name and pressing Enter. Type quit , and press Enter to exit python. Learn how to make a directory in the PowerShell Terminal. Learn how to change into a directory in the PowerShell Terminal. Make the file, Save or Save As Go back to PowerShell Terminal using just the keyboard to switch windows. Back in PowerShell Terminal , list the directory to see your newly created file.

When I run python3. Linux Linux is a varied operating system with many different ways to install software. Use your package manager to install Python 3. Use your Linux package manager, and install the Atom text editor.

You run things in Terminal by just typing the com- mand name and pressing Enter. Type quit and press Enter to exit python.

Learn how to make a directory in Terminal. Learn how to change into a directory in Terminal. Typically, you will make the file, Save or Save As Back in Terminal, list the directory to see your newly created file.

Finding Things on the Internet A major part of this book is learning to research programming topics online. If you can find the answers to your questions online, then you are one step closer to not needing me, and that is my goal. Thanks to search engines such as Google you can easily find anything I tell you to find. Type: python3 list functions. Read the websites listed to find the best answer.

Warnings for Beginners You are done with this exercise. This exercise might be hard for you depending on your familiarity with your computer. If it is difficult, take the time to read and study and get through it, because until you can do these very basic things you will find it difficult to get much programming done.

If someone tells you to stop at a specific exercise in this book or to skip certain ones, you should ignore that person. Anyone trying to hide knowledge from you, or worse, make you get it from them instead of through your own efforts, is trying to make you depend on them for your skills. A programmer will eventually tell you to use macOS or Linux.

If he likes control and has a huge beard, he will or ze will if you prefer non-gendered pronouns of humans with beards tell you to install Linux. Again, use whatever computer you have right now that works.

All you need is an editor, a terminal, and Python. Write exercises using the text editor. Run the exercises you wrote. Fix them when they are broken. Anything else will only confuse you, so stick to the plan.

These are different from software for writing stories and books because they work with the unique needs of computer code. I recommend Atom in this book because it is free and works nearly everywhere. Keep in mind that these projects may be abandoned, dead, or not work anymore on your computer.

If you already know how to use Vim or Emacs then feel free to use them. If you have never used Vim or Emacs then avoid them. Programmers may try to convince you to use Vim or Emacs, but this will only derail you. Your focus is learning Python, not learning Vim or Emacs. If you skipped Exercise 0, then you are not doing this book right. I said not to use one in Exercise 0, so you should not use one.

If you skipped Exercise 0 please go back to it and read it. You should have spent a good amount of time in Exercise 0 learning how to install a text editor, run the text editor, run the terminal, and work with both of them. You will not have a good time. Type the following text into a single file named ex1. Python works best with files ending in. All of those differences are fine. When you create this file, keep in mind these points: 1. I did not type the line numbers on the left.

I have the print at the beginning of the line, and it looks exactly the same as what I have in ex1. Exactly means exactly, not kind of sort of the same. Every single character has to match for it to work. In Terminal run the file by typing: python3. If not, you have done something wrong. No, the computer is not wrong. Even I make many of these mistakes.

We ran our command in the Terminal to run the ex1. Python tells us that the file ex1. It prints this line of code for us to see it. Notice the missing " double- quote character? Study Drills The Study Drills contain things you should try to do. For this exercise, try these things: 1. Make your script print another line. Make your script print only one of the lines. Put a octothorpe character at the beginning of a line. What did it do? Try to find out what this character does.

Pick the one that makes you chill out. How do you get colors in your editor? Save your file first as a. I get SyntaxError: invalid syntax when I run ex1. You are probably trying to run Python, then trying to type Python again. Close your Terminal, start it again, and right away type only python3. I get can't open file 'ex1. You need to be in the same directory as the file you created. Make sure you use the cd command to go there first. You most likely took the code in my ex1.

Your file has to be exactly like mine. They are used to tell you what something does in English, and they are used to disable parts of your program if you need to remove them temporarily.

It is important for you to understand that everything does not have to be literal. In fact, I could work with any text editor and the results would be the same. This will run. Take your ex2. Start at the last line, and check each word in reverse against what you should have typed.

Did you find more mistakes? Fix them. Read what you typed above out loud, including saying each character by its name. Common Student Questions Are you sure is called the pound character? I call it the octothorpe because that is the only name that no one country uses and that works in every country. Why does the in print "Hi there. The in that code is inside a string, so it will be put into the string until the ending " character is hit. Pound characters in string are just considered characters, not comments.

How do I comment out multiple lines? Put a in front of each one. How do I do that? Some coun- tries use the Alt key and combinations of other keys to print characters foreign to their language.

Why do I have to read code backward? This catches errors and is a handy error-checking technique. If they were math geniuses, they would be doing math, not writing buggy web frameworks so they can drive race cars. This exercise has lots of math symbols. As you type this one in, say the name. When saying them feels boring you can stop saying them.

After you type in the code for this exercise, go back and figure out what each of these does and complete the table. Compare each line of your file to my file. How about some more. Is it greater? True Is it greater or equal? True Is it less or equal? False Study Drills 1. Above each line, use the to write a comment to yourself explaining what the line does. Remember in Exercise 0 when you started python3. Start python3. Find something you need to calculate and write a new.

Rewrite ex3. What is the order of operations? The next step is to learn about variables. If you get stuck with this exercise, remember the tricks you have been taught so far of finding differences and focusing on details: 1.

Write a comment above each line explaining to yourself what it does in English. Read your. Find out how to type it if you do not already know.

We use this character a lot to put an imaginary space between words in variable names. There are only 30 drivers available. There will be 70 empty cars today. We can transport We have 90 to carpool today. We need to put about 3. Make sure you use line numbers and explain why. Here are more study drills: 1.

I used 4. Remember that 4. Write comments above each of the variable assignments. Try running python3. Popular variable names are also i, x, and j. Very simple. Imagine you have a file with 16 lines of code in it. Start at line 16, and compare it to my file at line Why did you use 4. It is mostly so you can then find out what a floating point number is and ask this question.

See the Study Drills. A string is how you make something that your program might give to a human. You print strings, save strings to files, send strings to web servers, and many other things. Strings are really handy, so in this exercise you will learn how to make strings that have variables em- bedded in them.

Put these variables in there. He's 74 inches tall. He's pounds heavy. Actually that's not too heavy. He's got Blue eyes and Brown hair. His teeth are usually White depending on the coffee.

If I add 35, 74, and I get Study Drills 1. Try to write some variables that convert the inches and pounds to centimeters and kilograms. Do not just type in the measurements. Work out the math in Python. No, 1 is not a valid variable name. They need to start with a character, so a1 would work, but 1 will not. How can I round a floating point number? You can use the round function like this: round 1.

Why does this not make sense to me? Try making the numbers in this script your measurements. Keep going and more exercises will explain it more. In this exercise we create a bunch of variables with complex strings so you can see what they are for.

First an explanation of strings. Python knows you want something to be a string when you put either " double-quotes or ' single-quotes around the text.

You saw this many times with your use of print when you put the text you want to go inside the string inside " or ' after the print to print the string. Strings can contain any number of variables that are in your Python script. We will now type in a whole bunch of strings, variables, and formats, and print them.

You will also practice using short abbreviated variable names. Those who know binary and those who don't. I said: There are 10 types of people. I also said: 'Those who know binary and those who don't. False This is the left side of Go through this program and write a comment above each line explaining it. Find all the places where a string is put inside a string. There are four places. Are you sure there are only four places?

How do you know? Maybe I like lying. Break It You are now at a point where you can try to break your code to see what happens.

Think of this as a game to devise the most clever way to break the code. You can also find the simplest way to break it. Once you break the code, you then need to fix it. Give your friend your ex6. Then you try to find their error and fix it. Have fun with this, and remember that if you wrote this code once you can do it again. If you take your damage too far, you can always type it in again for extra practice. The purpose is to build up your chops. See you in a few exercises, and do not skip!

Do not paste! Its fleece was white as snow. And everywhere that Mary went. Go back through and write a comment on what each line does. Read each one backward or out loud to find your errors. From now on, when you make mistakes, write down on a piece of paper what kind of mistake you made.

When you go to the next exercise, look at the mistakes you have made and try not to make them in this new one. Remember that everyone makes mistakes. They make mistakes all the time. Break It Did you have fun breaking the code in Exercise 6? Your goal is to find as many different ways to break your code until you get tired or exhaust all possibilities. Is it normal to write an English comment for every line of code like you say to do in Study Drill 1?

No, you write comments only to explain difficult to understand code or why you did something. Why is usually much more important, and then you try to write the code so that it explains how some- thing is being done on its own.

However, sometimes you have to write such nasty code to solve a problem that it does need a comment on every line. When you see me write formatter. Take the formatter string defined on line 1.

Call its format function, which is similar to telling it to do a command line command named format. This is like passing arguments to the command line command format. This is what print is now printing out. Do your checks, write down your mistakes, and try not to make the same mistakes on the next exercise. Python recognizes True and False as keywords representing the concept of true and false. No, you should learn to use the command line.

It is essential to learning programming and is a good place to start if you want to learn about programming. IDLE will fail for you when you get further in the book. I start with code that you might not understand, then more exercises explain the concept. With the three double-quotes. We'll be able to type as much as we like.

Even 4 lines if we want, or 5, or 6. Check your work, write down your mistakes, try not to make them on the next exercise. Are you breaking your code and then fixing it? You have to type them like """ and not " " ", meaning with no spaces between each one. What if I wanted to start the months on a new line? Most programming errors in the beginning and even later are simple spelling mistakes, typos, or getting simple things out of order.

In Exercise 9 I threw you some new stuff, just to keep you on your toes. I showed you two ways to make a string that goes across multiple lines. These two characters put a new line character into the string at that point. An important escape sequence is to escape a single-quote ' or double-quote ".

Imagine you have a string that uses double-quotes and you want to put a double-quote inside the string. If you write "I "understand" joe. To solve this problem you escape double-quotes and single-quotes so Python knows to include them in the string.

In this exercise the spacing is important to get right. You may not use many of these, but memorize their format and what they do anyway. Try them out in some strings to see if you can make them work. Escape What it does.

Memorize all the escape sequences by putting them on flash cards. Use ''' triple-single-quote instead. Can you see why you might use that instead of """? Combine escape sequences and format strings to create a more complex format. Should I continue? Yes, keep going. Sometimes, though, you may need to go back a few exercises and do them again.

Think about why you would need this. They are different characters that do very different things. One concept I need you to understand is that each of these exercises can be combined to solve problems. Take what you know about format strings and write some new code that uses format strings and the escape sequences from this exercise.

Go with the ''' triple-single-quote style for now, but be ready to use either depending on what feels best or what everyone else is doing. You are doing a lot of printing to get you familiar with typing simple things, but those simple things are fairly boring. What we want to do now is get data into your programs. This is a little tricky because you have to learn to do two things that may not make sense right away, but trust me and do it anyway.

It will make sense in a few exercises. Most of what software does is the following: 1. Take some kind of input from a person. Change it. Print out something to show how it changed. This tells print to not end the line with a newline character and go to the next line. Can you find other ways to use it? Try some of the samples you find. First thing is, go back and make the code exactly like mine.

Next, run the script, and when it pauses, type your height in at your keyboard. For input you can also put in a prompt to show to a person so he knows what to type. This is how you ask someone a question and get the answer. This means we can completely rewrite our previous exercise using just input to do all the prompting. In Terminal, where you normally run python3. Read what it says. Get out of pydoc by typing q to quit.

Look online for what the pydoc command does. Use pydoc to also read about open, file, os, and sys. Exit out of python3. Why does my pydoc not pause like yours does? Sometimes if the help document is short enough to fit on one screen then pydoc will just print it. When I run pydoc I get more is not recognized as an internal.

Some versions of Windows do not have that command, which means pydoc is broken for you. You can skip this Study Drill and just search online for Python documentation when you need it. Try this, and then try to print out what you type.

You know how you type python3. Well the ex Rather than give you all the features at once, Python asks you to say what you plan to use. This keeps your programs small, but it also acts as documentation for other programmers who read your code later.

This variable holds the arguments you pass to your Python script when you run it. In the exercises you will get to play with this more and see what happens. Hold Up! I just used that name because I needed to trick you into learning what they are without jargon. Before you can continue, you need to learn their real name: modules. Pay attention! You have been running python scripts without command line arguments. If you type only python3. Pay close attention to how I run it.

This applies any time you see argv being used. Try giving fewer than three arguments to your script. See that error you get? See if you can explain it. Write a script that has fewer arguments and one that has more. Make sure you give the unpacked variables good names. Combine input with argv to make a script that gets more input from a user. Just use argv to get something, and input to get something else from the user. Remember that modules give you features.

Remember that an important skill is paying attention to details. If you look at the What You Should See section you see that I run the script with parameters on the command line. All books on the edubookpdf. If you feel that we have violated your copyrights, then please contact us immediately click here. Buy Me a Coffee. All Rights Reserved.

Theme by. Facebook 0 Tweet 0. Previous Article Tired of reading tutorials? Check out those awesome Youtube channels to learn to code for free!



0コメント

  • 1000 / 1000