Learning Python — The Pretty Devil
Hurdles faced by people learning python
Switching from Java to python was not difficult for me. Though my code was not pythonic, I could code and have it up and running without any problem. When I was working at Focus infotech we used to conduct workshops and seminars for building chatbots, where python is a pre-requisite. After conducting a few hands-on workshops, I noticed a few issues that most beginners to Python faced repeatedly.
I want to compile it into a list because I want to send a message to beginners out there that it is ok to make these mistakes while learning python and you are not alone. For people who teach python here is a few key points to keep in mind while teaching Python to complete newbies.
A Bit of a Background
Most of our students came with a knowledge of C type languages — C/C++/Java. They get theoretical knowledge of these languages as a part of their curriculum. The patterns of problems were similar across the board. Here is a list of a few problems.
The Problems
Which version of python?
Having python versions ranging from 2.7 to 3.7 confuses beginners. They had no clear direction on which one to choose. It is the first question asked by anyone who wanted to learn python.
shell vs. file
Most of the Python programmers understand how to leverage python shell and switch in and out of it. But for newbies, it was very confusing, mostly because they came from a background of compiled languages. Interactive shells and the ability to type and execute small code snippets was unknown to them. During their labs, they had written pieces of code using editors, compiled and fixed errors and iterated until they got the program working.
Interactive input
Input in the shell was another problem. We used to show them simple programs to accept input from the console and perform some manipulations. input() was particularly difficult for them. The program was waiting for them to give some input and they were waiting for the program to do something. That’s when I realized that we should always teach input statement with a prompt like raw_input("Enter your name ::")
Use Of colon
The students were so used to semi-colons of C/C++/Java that they mistook colons for semi-colons. Looking at the program projected on a screen did not help much, and they scratched their heads to find out whether it is a colon or semicolon. Most of them went with semi-colon since that is what other languages do. Thankfully I have never seen anyone putting semi-colon for all the lines.
Indentation
It is another nightmare for new Python programmers. Curly braces gave a visual attire to code blocks. Though python’s strict indentation make the code look neat and clean for beginners, it is a battlefield where they never knew whether a particular block should be indented in or out.
Data types
Python’s weak and dynamic typing confused beginners. It was difficult because the code would give them no idea whether it is an integer or float or string. They all looked the same, to them. The lead to a host of problems.
Prints and Operations
Since the data-types are not obvious, they don’t know how to print those variables or how to play around with them. For ex., while learning lists, they were happy to create a list of 5 elements and print it using print statement. However, when you ask them to print the items in a list vertically, they panicked since they had no idea how to couple it up with Python’s for loop.
How and when to use dictionaries?
Things get worse when they discovered dictionaries since no other programming language had ever introduced such a data structure to them. While Java has HashMaps, they were not extensively used in Java programming examples they had seen. We realized that the best way to introduce data structures like dicts would be to show a table and show how to convert it into a dictionary representation.
There were other problems too. Like how to operate over the dictionary. How to find a key/value is present in the dictionary, return types on functions and so on.
Takeaways
- If your audience has prior programming knowledge, it is better to start with a comparison of what they already know and map it to similar programming constructs in Python.
- If they have never seen programming in life, a turtle graphics program will inculcate more interest than a _“hello world” _program.
- Python is not a difficult language to learn, but it needs a high-level view and an open mind to suck it all, especially if you’re from Java or C++’s of the world.
Top comments (0)