What are some of the common frustrations one faces while learning Python?


In the current era of computers and software everywhere, we have thousands of new joinees everyday who want to learn the essential skill of programming. Among beginners, Python is one of the most popular languages to start with, due to its dynamic typing, ease of learning and wide range of applications. However, there are a few recurring frustrations of new Python programmers who are just starting out on their programming journey. We will talk about them here.

Problems Faced

  • Unavailability of good learning resources

  • Facing compiler or runtime mistakes

  • Executing an external command through Python

  • Enumerating in Python

  • Working with modules

Problem 1: Unavailability of Good Learning Resources

Although Python is one of the most popular and widely-used programming languages out there, learning resources for the same are scanty. There are a few good resources, although they are not curated to contain everything, and it results in breaks in the learning curve. 

Also, a vast programming language like Python has applications in almost all major tech fields in today’s world, ranging from Machine Learning modules to Backend development of products. To search for everything at one place results in returning empty handed, and it is very important to look for tutors and lessons on the correct platforms. Several reputed online coding academies are available, where industry experts teach beginners on taking the right steps in learning the skill they are looking for. This is one effective way to overcome this problem.

Problem 2: Facing Compiler or Runtime Mistakes

In general, like most common programming languages, mistakes in Python can either be compile-time or runtime mistakes. Compile-time mistakes are mostly syntax errors, or some other form of faulty code which is detected when the compiler runs through the code while it is learning how to execute the entire code block. If there is a compiler error, the program execution stops and an error message is shown.

Compare this to runtime errors, which occur when the program has been compiled successfully and is running, but there is some bug affecting its performance every time it runs. The side effect of runtime errors can be pretty large, as they are usually overlooked while writing the code and compiling, but can result in memory leakage, loss of data and other major problems. Fortunately, Python has a shell script, which helps in debugging errors. Also, debuggers like Python pdb help in spotting and removing code efficiently.

Problem 3: Executing an External Command Through Python

At some point in one’s Python programming career, there might be a situation where a terminal command needs to be executed in a Python script. Usually these happen when different pieces of code or modules from different programs or scripts are combined together to create a program. This can be achieved through the call function under the subprocess module.

Syntax

from subprocess import call
call('function name')

Here, the call function is first imported from the subprocess module. Then the call function is called and the function name of the function which is required to be called is passed as an argument. This is a very simple syntax which can be typed in the terminal to call a function externally.

Algorithm

Step 1 − Import the call function from the subprocess module

Step 2 − Call the ‘call’ function and pass the function name as argument

Step 3 − Receive the output

Problem 4: Enumerating in Python

An array is one of the most commonly used containers in most languages. In Python, the list is a similarly styled container which is used in most basic implementations. However, as array iteration uses indices, in Python the implementation of lists is different. Here the array elements can be traversed by simple code instead of using indices. Thus for accessing individual elements, we use the enumerate() function in Python.

Syntax

for item in enumerate(x):
   print item

Here, we use a for loop like in other languages such as C++, but we avoid using the indices. The enumerate() function takes care of iterating through the array. The name of the list is passed as an argument to the enumerate() function. The output is in the form of pairs, with each pair containing the list elements and their indices. We can also add conditions within the for loop for printing selected list elements.

Algorithm

Step 1 − Create the list and initialize with elements

Step 2 − Create the for loop with the initialize() function in the header

Step 3 − Pass the list name and add body to the for loop

Example

x = [10, 20, 30, 40, 50]
for item in enumerate(x):
   print item

Output

(0, 10)
(1, 20)
(2, 30)
(3, 40)
(4, 50)

Problem 5: Working with Modules

The Python language consists of extensively designed modules which contain a wide variety of functions. Along with this, custom modules can be created by programmers, and imported in other programs to use the functions present in that module, thereby helping in uniformity in code. However, if separate modules are imported, we need a special code block to prevent the compiler from executing the function as soon as it is imported, and wait until it is actually called in the main function while runtime.

Syntax

def function():
   //body
if __name__ == '__main__':
function()

Here, first the function is defined and then, the specific line is added. This line of code prevents execution of the function when it is imported, rather waits until the function call is made in the main function during runtime.

Example

def print_world():
    print ("Hello World!!")
if __name__ == '__main__':
 print_world()

Output

Hello World!!

Conclusion

In this article, we have gone through some of the common frustrations that new programmers face while learning Python. Although the list of problems can be endless, all problems cannot be solved here and might need a detailed understanding. We hope this article provided some useful solutions to whomever may need it

Updated on: 11-May-2023

43 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements