Reputation: 786
It will probably astound you how basic these questions are, but please bear with me! And if there is a better place to ask, I would be appreciative for a migration.
I am looking at two Python tutorials, one of which is "Learn Python the hard way". I am in no condition to evaluate the quality of the tutorials, so I have a few questions. (I have only just started LPTHW so I apologize if the answer comes 20 exercises later.)
In LPTHW, the exercises so far have been coding into Notepad++ and executing the txt document from a command line. In the other one, it was an "enter commands one by one into Python" tutorial. Question: which is more practical for a learner? "Both" is an acceptable answer.
In LPTHW, the first explanation of variables, the format character commands %s %d and %r are used. The exercise says "search the web to learn about all of them." I did a websearch and found someone saying "Don't use those, use the new ones." Question: is LPTHW out of date in this way, and should I be using "new ones"?
Upvotes: 2
Views: 527
Reputation: 932
I have been working through LPTHW for the last few months and am currently on ex50. My short answer is: take Shaw seriously and bust your ass working through LPTHW! You will see that you'll use both text editor and interactive sessions, so that is not a real concern. Shaw is not kidding about "hard," but that's because if you spend the time over the course of some months, and take the "extra credit" seriously, you're going to learn a ton.
When he says, "go read about blah," yeah, it's tough. But I quickly realized that "go read about" is a necessary skill (I guess I knew this already). Plus, it's permission to surf the web and get lost reading about python things that weren't in the assignment :)
Some tips from me:
Do this book first (much easier than LPTH): command line crash course. Take him seriously, make the flash cards. I was lucky and had two laptops side-by-side, one Windows 7, one Ubuntu linux. At this point, I've gravitated towards coding all in linux and I'm good enough at command line stuff that I'm actually wanting to learn Vim (a big surprise to me)
If you have a choice between linux and windows, you'll probably be happier using linux towards the end. I think everything is supported on Windows, but most of the help out there is geared towards linux. I had a goal of learning both side-by-side, but like I said above, at this point I read LPTHW on my Windows machine while I code on the Ubuntu machine
Do all the extra credit. But don't worry if you're confused. I found that later on, maybe the next day, maybe the next week, I'd go back and finally understand the extra credit from a previous exercise.
Of all the exercises so far, "Exercise 46: A Project Skeleton" was the most transformational for me. Around that point in the book, I started to get stuck and felt incompetent. But I kept struggling, and after a week or two (maybe 10 to 20 hours of working) something all of a sudden "clicked," and I now feel like I know something. I'd recommend doing the "required quiz" questions 3-6 repeatedly, until you can do it all from memory without looking anything up. On linux, you can do all of those questions just with the keyboard, and I realized how quickly things can be if you don't need the mouse. I think that's why I'm tempted to learn Vim.
Finally, while you're working through LPTHW, use python for small projects if possible. This is good motivation, and you're allowed to read ahead to figure out things like installing packages. I found that pretty early on, I was able to go onto github, find code that I needed, and adapt it for my own purposes. Even when much of it was mysterious, for example, if __name__ = '__main__': . I had no idea what that meant, but that didn't stop me from using python and wanting to learn more.
OK, good luck!
Upvotes: 1
Reputation: 9347
The Python repl is good for testing out built in functions, however as far as writing robust, complicated programs, you have to write to a file.
Although we are at Python 3.x, Python 2.x is still more widely used. %s is a place holder for a string, %d is a place holder for an integer and %r is a place holder for some python command.
For example:
a = "hello world"
b = "%s"
b%a == "hello world"
a = 10
b = "%d"
b%a == "10"
a = "%r"
a%range(10) == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" #since range(10) is a python function
#which returns the list of numbers
#from 0 to 10
Upvotes: 1
Reputation: 308763
Here's my take:
Upvotes: 1
Reputation: 437
1) Both. Creating scripts is what you would do with Python on a large scale. Using a Python shell is also good to show you that you can do simple scripting with tons of options via a command line and don't need to build/compile entire programs, etc like you do in other languages.
2) Formats change, but its not a big deal. Many people still use Python 2.x because Python3 introduced some unnecessary changes. Just look it up.
Upvotes: 1
Reputation: 19037
Upvotes: 3
Reputation: 122376
Typing Python code into the interactive interpreter is a good way to test things out, in particular if you don't want to create a file for it. It's useful to see what results functions return and to try anything out. But any programs you write will be stored in files of course. Both is indeed the answer because they're both used during development, just for different purposes.
The new method of formatting string is "thestring".format(...)"
, where ...
are all kinds of formatting options. This is indeed the new way of doing things and you should use that instead. The old formatting options make the code less readable (as you'd have to know the abbreviations with %
in them) and it's just a lot easier to write "string with values: {0} and {1}".format(3, 4)
.
Upvotes: 0
Reputation: 110
Idle would be a little quicker, or the pydev plugin for eclipse(would also give code completion etc), and you could write and run your code from one place either of these way, and out of date, really depends on your environment, also you can't go wrong with thenewboston tutorials on youtube
Upvotes: 0