Jump to content

Python Tips?

jappypack

I'm currently studying GCSE Computer Science. I'm loving the subject, and the programming language that's going to be assessed is Python. I'd like some tips for coding in Python, and programming in general! :)

Link to comment
Share on other sites

Link to post
Share on other sites

There is a bazylion of resources for Python on the web. Without any specifics it's hard to give any specific tips ;)

 

In general it's important to write clean, tested and good code, not just "any code" that happens to work. There is a good book - "Clean Code: A Handbook of Agile Software Craftsmanship"  by Robert C. Martin.

Link to comment
Share on other sites

Link to post
Share on other sites

Make a CodeAcademy account and go through the Python course. That's what I did for my national 5 (GCSE equivalent).

I had an account called Joegeddon active since April 20th 2015

Desktop

AMD Ryzen 5 2600 | XFX RADEON RX580 8GB XXX | 16GB 3000MHz DDR4 | Thermaltake Versa H22 | Corsair RM550x PSU | MSI AM4 B450M-A PRO Motherboard

1TB 7200RPM HDD | 500GB 7200RPM HDD | 500GB M.2 WD BLUE SSD

 

Laptop - Asus UX303UA

Intel i7 6500U | Intel 530 Graphics | 12GB 1600MHz DDR3 | 256GB SATA 3 SSD

Link to comment
Share on other sites

Link to post
Share on other sites

Get started with CodeAcademy, experiment yourself and always stick with conventions.

If you want to reply back to me or someone else USE THE QUOTE BUTTON!                                                      
Pascal laptops guide

Link to comment
Share on other sites

Link to post
Share on other sites

if you need any help you can also post here. Don't expect or even ask for the answer but hints on how to solve a problem. 

 

on a side note I do love python.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

In addition to the Unix philosophy as posted by @Name Taken (which is just a good philosophy in general to use as a starting point), there's the Zen of Python, which is more specific to Python itself and reflects a lot of the ethos and mindset of the language.  Open up your Python interpreter and type "import this" to read it.  Or find PEP 20.  Or I'll just paste it here:

 

Quote

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

 

One of the more important points in there is There should one one--and preferably only one--obvious way to do it.  That's kind of the unofficial/semi-official motto of Python (in direct response and contrast to Perl's "There's more than one way to do it").  You can think of this as meaning "the simplest and most obvious solution that gets the job done is usually the best one"--more complicated solutions often reach the point of diminishing returns, are less readable, and a bit less re-usable.  Use Python built-in functions when you can, avoid harder to read code if it only gets you marginal performance boosts or if performance isn't critical, etc.

Link to comment
Share on other sites

Link to post
Share on other sites

Assuming you started this year, my best advice (from someone doing the course myself), would be to get familiar with the language before you do things by downloading python and a good IDE (I'd recommend Pycharm) and trying it out at home. It's best to come to class with atleast a bit of an idea about the thing your doing, rather than have them teach you the whole thing in class.

 

TL:DR: Try it at home, not just at school.

Link to comment
Share on other sites

Link to post
Share on other sites

I recommend going on learn python the hardway. It is boring as hell but its very very good for learning. Don't skip anything even if you know it because he goes back and uses stuff created before.

 

I am current on exercise 45. Once you get around here you learn about nosy tests. No spoilers here but they are very good for testing your code and its automated.

 

at one point your given the tests and have to make the packages that will return the correct data to pass.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

 

22 hours ago, vorticalbox said:

I recommend going on learn python the hardway. It is boring as hell but its very very good for learning. Don't skip anything even if you know it because he goes back and uses stuff created before.

 

I am current on exercise 45. Once you get around here you learn about nosy tests. No spoilers here but they are very good for testing your code and its automated.

 

at one point your given the tests and have to make the packages that will return the correct data to pass.

Learn Python the Hard Way (and the other books by Zed Shaw) are excellently written, and I love their basic setup of "here is code, run it, then we'll talk about it."  That said, the Python book is written for Python 2, and takes a pretty hardline stance against Python 3 being important, which is irksome, since no real development has been done on Python 2 in several years beyond basic bugfixes and most everything is written in and for 3 now.  The rest of the book is great, but if you're only learning Python 2, you're gong to miss a lot of the really nice stuff added in 3.  So just something to be wary of.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Azgoth 2 said:

 

Learn Python the Hard Way (and the other books by Zed Shaw) are excellently written, and I love their basic setup of "here is code, run it, then we'll talk about it."  That said, the Python book is written for Python 2, and takes a pretty hardline stance against Python 3 being important, which is irksome, since no real development has been done on Python 2 in several years beyond basic bugfixes and most everything is written in and for 3 now.  The rest of the book is great, but if you're only learning Python 2, you're gong to miss a lot of the really nice stuff added in 3.  So just something to be wary of.

I like it because it I have to translate it into python 3. Some packages are different like the url I can never remember the name was split into request and some other.

 

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/12/2016 at 3:10 PM, vorticalbox said:

I like it because it I have to translate it into python 3. Some packages are different like the url I can never remember the name was split into request and some other.

 

 

I suppose that's fair.  That could be an interesting way to learn the ins and outs of Python 3 a bit better, now that I think about it.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×