Sei sulla pagina 1di 6

11 Things Every Python Developer Should

Know
Python is one of the best coding languages that a developer should learn to boot his or her career.
There are many big sites such as Instagram, Netflix, Uber, Pinterest, and Dropbox, which have
been created using python programming language. In this case, skilled Python programmers are in
high demand, not only because of the popularity of the language but mostly because it has grown
to become a solution to many different problems in the software development world. Python has
been used in various developments, such as web applications, machine learning, and data science.
As a Python fan, I believe that there are certain essential concepts or facts that every Python
developer should know. All these were important were necessary concepts within the period I
learned using Python as my main programming language. One needs to be familiar with sites such
as the official Python website, Python 2 and 3 documentations, and stack flow. In this article, I
will discuss the 12 Things Every Python Developer Should Know.

The Different Versions of Python


Programming Platforms
Although this is not a programming characteristic, it still remains to be crucial to understand the
latest versions of Python so that everybody is familiar with the programming language. Python
programming language versions are usually numbered as ABC, whereby the three letters epitomize
the significant changes that the programming language has encountered. For example, changing
from 2.7.4 to 2.7.5 shows that Python made some minor bug fixes to the platform, but going from
Python 2 to Python 3 shows a major change took place between the two versions. For you to
confirm your version of python program, you can use the statement:

import sys

print ("My version Number: {}".format(sys.version))


COPY SNIPPET

The Python Shell


The python shell comes auto-installed in the platform, and it can be executed by typing the
command python in the command line (in the Windows OS). This will provide the default version,
copyright notice, and r-angles >>> that ask for input. If your computer contains multiple versions
of Python, then you will have to add in the python3.3 version number to get the correct version.
Python shell allows a user to test some simple commands to detect whether there is a logical or
syntax error, thus help avoid consuming much time or memory.
Understand the Python Frameworks and
the Object Relational Mapper (ORM)
Libraries
Having a clear understanding of the Python frameworks is very important, but, that does not mean
that one has to know all of them. Based on the project that you are trying to execute, you will be
required to know the most important ones for that project, but the most popular ones that are used
often are CherryPy, Flask, and Django. Moreover, one needs to understand how to connect and
use applications through the ORM, such as the Django ORM and SQLAlchemy. This makes it
easier, efficient, and faster compared to writing an SQL.

Understand the Difference between the


Front-End and Back-End Technologies
The front-end is what a user sees when visiting a page while the back-end is what happens behind
the scenes. The back-end is where the programs are executed and queries data from the database
to display it to the website. Python is one of the programming languages used in developing the
back-end. However, a python developer is required to link with the front-end developers to link
the client-side with the server-side. In this case, it is essential to understand how the front-end
work and how the application will appear.

It Is Essential to Know How to Use the 'sys'


and 'os.'
These modules are useful to a Python developer since they provide generality and consistency.
The sys allows the developer to use the command line inputs to the program, to avoid going back
to the text-editor or amend the program before re-executing. Modifying the inputs on the command
line is faster and more efficient compared to retyping the variables in the text editor. This can be
done using the sys.argv, which will take in the inputs from the command line. In addition, one can
also ensure that the user inputs the accurate parameters. Other than speed, the command line
arguments can be employed as part of a process that automates the script repeatedly.

List Comprehension Exemplifies the


Simplicity and Beauty of Python
Python 2.7.5 documentation offers a vivid description of how to list comprehension is important
to a developer. A list display produces a new list object since the contents are usually specified
either as list comprehension or a list of expressions. Whenever a programmer uses a comma-
separated list of expressions, the elements are usually evaluated from left to right and then arranged
in that order within the list object. Whenever a list comprehension is used, it contains a single
expression that is accompanied by at least one for clause and zero or more for or if clauses. In such
a case, the new list elements will be those that will be produced by bearing in mind that each of
the if or if clauses a block, nested from left to the right side, and assessing the expression to come
up with a list element whenever the innermost block is reached.

list2 = [(x, x**2, y) for x in range(5) for y in range(3) if x !=


2]

print(list2)

'''
list2 = [(0, 0, 0), (0, 0, 1), (0, 0, 2), (1, 1, 0), (1, 1, 1), (1,
1, 2), (3, 9, 0), (3, 9, 1), (3, 9, 2), (4, 16, 0), (4, 16, 1), (4,
16, 2)]

This expression can be easily understood as:

list2 = [(x, x**2, y) for x in range(5):


for y in range(3)
if x != 2]

'''
COPY SNIPPET
Just as the Python 2.7.5 documentation states, one can create a nested list via list comprehension,
and it is mainly significant whenever a developer needs to initiate a matrix or a table.

Classes and Functions Definition


The def makes function definition in Python to be easier. For example:

def count_zeros(string):
total = 0
for c in string:
if c == "0":
total += 1

return total

# 3
print (count_zeros ('00102'))
COPY SNIPPET
Moreover, the recursive functions are also not complicated, and they have a similar character as
some object-oriented programming (OOP) languages. Unlike other programming languages such
as Java, Python uses few classes, making a developer's expertise in the expertise to be quite limited.
The Python 2.7 documentation describes classes as:

Python classes provide all the standard featutes of Object Otiented Programming: the class
inheritance mechanism allows multiple base classes, a derived class can override any methods of
its base class or classes, and a method can call the method of a base class with the same name.
Objects can contain arbitrary amounts and kinds of data. As is true for modules, classes partake of
the dynamic nature of Python: they are created at runtime, and can be modfied further after
creation.

File Management
Most python scripts use files as their inputs, thus making it important to understand the best way
of incorporating the files in your code. In this case, the open keyword serves a great purpose since
it is straightforward, and the programmer can loop through the file to analyze it in each line. The
alternative is that one can employ readlines () method which helps create a list that comprises of
each line in the file, but it is only efficient for smaller files.

f = open ('test.txt', 'r')


for line in f:
f.close()
COPY SNIPPET
The f.close() helps in freeing up memory that has been occupied by the open file.
Basic Memory Management and Copying
Structures
While making a list in Python since easier, copying is not as straightforward as making a list. In
the beginning, I often made separate copies of lists using the simple assignment operators. For
example:

>>> list1 = [1,2,3,4,5]


>>> list2 = list1
>>> list2.append(6)
>>> list2
[1, 2, 3, 4, 5, 6]
>>> list1
[1, 2, 3, 4, 5, 6]
COPY SNIPPET
This is a case where making lists that are equal to other lists creates two variable names that point
to a similar list in the memory. This applies to any “container'' item such as the dictionary. Since
the simple assignment operators do not generate distinct copies, Python contains generic copy
operations and a built-in list statement which help is generating more distinct copies. Moreover,
slicing can also be used in generating distinct copies.

>>> list3 = list(list1)


>>> list1
[a, b, c, d, e, f]
>>> list3
[a, b, c, d, e, f]
>>> list3.remove (3)
>>> list3
[a, b, c, d, e, f]
>>> list1
[a, b, c, d, e, f]
>>> import copy
>>> list4 = copy.copy (list1)
COPY SNIPPET
However, a developer may encounter containers that are within other containers, such as
dictionaries containing dictionaries. In this case, using the direct operation will make any changes
to one dictionary to be reflected in the larger dictionaries. But, one can solve this using the deep
copy operation, which will help in copying every detail. This operation is memory-intensive
compared to other copying solutions.

Understand the Basic Concepts of


Dictionaries and Sets
Although lists are the most common types of data structures that are used in Python, one can still
use sets and dictionaries. A set is a container that contains items in a similar way as a list, but it
only contains distinct elements. If an element x is added to a set that already contains another
element x, the set will not change. This makes it advantageous over lists since there will be no
need for duplication as required in lists. Moreover, creating a set that is based on the pre-existing
list is more manageable since one only inputs the set (list_name). However, one disadvantage of
the sets is that they do not support elements indexing, making it lack order. On the other hand,
dictionaries are also important data structures that pair up elements together. One can search for
values efficiently using a key consistently.

Slicing
This is a process that involves taking a subset of some data, and it is mostly applied to lists and
strings. Slicing is not only limited to just eliminating one element from data. In this case, for
programmers to have a better intuition about slicing, they have to understand how the process of
indexing works for negative numbers. In the Python documentation, there is an ASCII-style
diagram in the Strings section which advocates that the developer should think about Python
indices as pointing between data elements. One can employ the Python shell to play around with
semi-complicated slicing before using your code.

Potrebbero piacerti anche