When learning python, the first thing to do is... well... learn python. There is a lot to learn. A basic understanding of the language covers things like:
- Basic expressions (variables, statements)
- What is a function
- Flow control (if, iterations)
- Basic data types (strings, integers, floats)
- Data building blocks (lists, dictionaries, tuples)
- File Handling
- Classes (objects, methods, inheritance)
There are a lot of resources on the web that can help with getting started. You can also waste a lot of time looking around. I think getting a decent book and getting serious about it will you well down the road with getting started learning python.
Check out this article about python reading material. Here's some books that can be read online for free that I like:
The real key is to get some fundamentals under your belt and then just put what you've learned into practice.
Getting into Intermediate Mode
There is where I found myself stuck for awhile. I had written several utilities that I found useful and could lay out an application and work my way through it.
But, I was kind of stuck. Mainly the world of python is so vast, you find yourself asking, "OK, now what?" "Where do I go next?"
For that I'm focusing in several areas:
I kept hearing that having tests were a big part of solid python application development. So, start writing tests. I have, and it's blowing my mind. Yes, you need to pick a test tool and learn it (pytest for me). Yes, you have to write tests to exercise your code. Yes, there is this thing called test driven development where you write the tests first, before you write your code. I'm not there yet, but at least I try to write tests along with my code now.
But, what I didn't expect, is that thinking about testing changes the way I think about the classes and functions that make up my application. It is forcing me to write clearer, easier to understand code. That's a good thing.
Sphinx is my go to documentation tool. Writing documentation is having a positive impact in a couple of areas.
First, it forces me to write clearer docstrings. Someone else may be reading them in the future (and it might be you). They need to be written in a way that conveys what the code is all about.
Secondly, it is causing me to focus on using type hints. Having type hints, at least in you function definitions produces better documentation.
Third, I have to think like a user when writing up how to use the application. Having a user's perspective is going to make the resulting application a lot friendlier for someone else to use.
Grrr. If python has a weak spot, it is probably in the ease of distributing your masterpiece of code to someone else. If they can't install it easy, they aren't going to use it. I'm still digging into this one and haven't finallized my toolset. So far, I've mainly distributed my applications on Windows using tools like py2exe that create an executable.
This is really the fun part. For many people, learning python is about finding ways to tackle problems they want to solve. Once you have the basics under your belt, you can start to specialize in the areas that really interest you. Things like web scraping, web development, data manipulation, and so on. It is limitless.
But, you know enough to build applications in areas you only dreamed of before. A major tool in this area for me is learning Flask. That enables me to build web sites and APIs.
Specialization is really about tying other technologies into python. This includes things like talking to databases, reading and writing Excel files, reading PDF files, creating graphs and graphics. Time to revisit "Automate the Boring Stuff".
Lately I've been asking myself, what do I consider to be an advanced stage of python learning. I've come up four areas. These thoughts may change as I grow.
- Language Mastery
- Problem Solving
- Data Science
- Complex Applications
A lot of developers "love" python. They find it to be an elegant and expressive language. There is a way of writing code that is considered to be more "pythonic". To me that means using the features of the language to write clear and simple code.
Use the language to efficiently solve difficult problems. Digging into advanced algorithms.
Very similar to problem solving, but to also understand the nuances of data and use python to bring clarity.
Use the language to build major tools that provide benefits for many users.
The great thing about python is that it is FUN. It is fun on day 1 when you learn to write beginner code like:
name = input("What is your name? ") if name == "Mike": print("Hello " + name + ". You are awesome!") else: print("Hello " + name + ".")
But, yet it is still fun years later when you're using it to tackle all kinds of serious projects. Really, there's no point in coding if it's not fun.