A Better Way to Learn Python Part 1
In this article, take a look at some courses to learn Python as well as a few example programs.
Join the DZone community and get the full member experience.Join For Free
Python is just the language for you. The smart way to learn Python is by practicing more programs in Python. In this series, we are going to write more and more programs to get clarity over a concept. At the end of the series, we will be ready for production quality code experience and we will try to cover most aspects of the readiness.
This is part 1 of the series, where we will focus on how to start and learn the basics or fundamentals of Python. All the courses that we will discuss are free and are some of the best course to learn and digest Python easily. Practice as much as you can and follow the steps like writing code, failing, analyzing, fixing it, writing it again, and so on. So by practicing writing more pythonic code, we will learn more and get a hands-on experience for developing production-ready code.
Warning: These are not the best performant programs. There may be better than these.
In systems design, a fail-fast system is one which immediately reports at its interface any condition that is likely to indicate a failure. Fail-fast systems are usually designed to stop normal operation rather than attempt to continue a possibly flawed process. [wiki]
" In theory, theory and practice are the same. In practice, they are not. " Dr. Albert Einstein
Let's see where to start, what IDE to use, where to learn and learn for free.
- Create a git repo for python learning and write one program every single day and checkin your code to this repo. https://github.com/simplymanas/python-learning
- Learn it from the best and trusted source. https://docs.python.org/3/tutorial/ official python tutorial and documentation https://docs.python.org/3/reference/index.html#reference-index
- Getting started, still you can go for official guide. https://www.python.org/about/gettingstarted/
- IDE: For me, I found Visual studio code is the best. https://code.visualstudio.com/docs/python/python-tutorial
- Unit Test: help you write better programs https://docs.pytest.org/en/stable/
- Practice sethttps://leetcode.com/ (remember a program a day)
- Take a challenge, Code minimum an hour every day for the next 100 days. https://www.100daysofcode.com/
- From zero to herohttps://www.freecodecamp.org/news/learning-python-from-zero-to-hero-120ea540b567/ one of the best and absolutely free course
- Scientific Computing with Python Certification (300 hours) #FREE https://www.freecodecamp.org/learn
- We miss discipline and not time (hope you have learned some skills during the lock down time)
We are not going to repeat the fundamentals; you can read it yourself. There are plenty of blogs and tutorials available for learning Python. In this series, we will write a few programs to prove that the concepts work.
After learning the first few sessions of Python and becoming comfortable with the programming construct, let's jump to a few programs (in no specific order).
Return number of days in a month where the year and month is given.
Here we are also checking if the given year is a leap year or not.
You will note we are using list, if condition, function, comments, and a few operators of Python.
How many times a letter is repeated in a given string.
We are using a library and have imported it (https://docs.python.org/3.8/library/collections.html)
Counter is a
dict subclass for counting hashable objects. (From https://docs.python.org/2/library/collections.html)
Prime number test. We are using the for loop here and the catch is there is one else statement in python for loop as well.
When used with a loop, the
else clause has more in common with the
else clause of a
try statement than it does with that of
if statements: a
else clause runs when no exception occurs, and a loop’s
else clause runs when no
break occurs (From https://docs.python.org/3/tutorial/controlflow.html)
Remember in school, the teacher used to ask us to write a line 10 times. The perfect solution is here. You can also use the range keyword to achieve this; try that at home (no risk).
It is more like a power pack in a single line of python and a better and concise way to use a list. Sometimes it is less efficient and harder to read, so use it when you think you are better at this.
For your homework - Is this better at readability than a lambda?
In the next part, we will write more programs and explore more features of Python. Once you read a concept here, go back and learn it from the resources and write a program of your own and check in to your git. You are done for the day: add a point for yourself, a diamond point.
A Few More Challenges
Keep smiling and keep learning.
Opinions expressed by DZone contributors are their own.