Python Tips

Programmer Guido van Rossum created the Python programming language in 1990. Van Rossum designed Python to be easily readable even by new programmers, which is why the syntax differs from C and Java. Python is an interpreted programming language; it requires another program, an interpreter, to execute it. Both Python and the interpreter are available as free downloads from the Python Software Foundation.

  1. Modules

    • When you write a sizable Python program, breaking it down into several files makes it easier to manage. By including several functions in one file, you make it into a module that you can import into other Python scripts and programs. Each file must have a .py extension. To review the internal documentation for any particular module, give Python the name of the module followed by doc. Python comes with a library of standard modules available for use.


    • After you write your program, test it to make sure it runs correctly. If it works, but runs slowly, optimize it to make it more effective. Python has a number of profiling modules to help with this by looking over your program and identifying the bottlenecks. Rewrite the weak points without disturbing the code that works smoothly. Run the program again after your rewrite to confirm that it still works properly.


    • Two common categories of Python program mistakes are exceptions and syntax errors. New programmers make lots of syntax mistakes, such as not including a colon to separate a code block. Python's parser tool helps you locate the problem. Exceptions are syntactically correct code that doesn't execute properly. If you've created an exception Python recognizes, Python may inform you when you run the program that you have a NameError or a TypeError and explain the context in which it happened.

    Other Languages

    • It's important to remember that Python isn't C, C++ or Java; it doesn't follow the same rules. Most compiled programming languages use semicolons to separate statements and curly brackets to separate code blocks. Python uses carriage returns for statements; it uses a colon and indentation for code blocks. Python also offers dynamic typing. Unlike Java and C++, you never have to explicitly identify a data type; Python tracks data types internally.

Related Searches



Related Ads