Fundamentals Concepts in Python - IT magazine

IT magazine

Knowledge that matters

Fundamentals Concepts in Python

Share This

There are five fundamental concepts in Python.
  1. Case Sensitivity: All variables are case-sensitive. Python treats ’number’ and ’Number’ as separate, unrelated entities.
  2. Spaces and tabs don’t mix: Because whitespace is significant, remember that spaces and tabs don’t mix, so use only one or the other when indenting your programs. A common error is to mix them. While they may look the same in editor, the interpreter will read them differently and it will result in either an error or unexpected behaviour. Most decent text editors can be configured to let tab key emit spaces instead.
  3. Objects: In Python, like all object oriented languages, there are aggregations of code and data called Objects, which typically represent the pieces in a conceptual model of a system. Objects in Python are created (i.e., instantiated) from templates called Classes. They have ”attributes”, which represent the various pieces of code and data which comprise the object. To access attributes, one writes the name of the object followed by a period (DOT) followed by the name of the attribute. Code attributes are called ”methods”.  To execute the code in a method, use a matched pair of parentheses surrounding a comma separated list of whatever arguments the method.
  4. Scope: In a large system, it is important that one piece of code does not affect another in difficult to predict ways. One of the simplest ways to further this goal is to prevent one programmer’s choice of names from preventing another from choosing that name. Because of this, the concept of scope was invented. A scope is a ”region” of code in which a name can be used and outside of which the name cannot be easily accessed. There are two ways of delimiting regions in Python: with functions or with modules. They each have different ways of accessing the useful data that was produced within the scope from outside the scope. With functions, that way is to return the data. The way to access names from other modules lead us to another concept.
  5. Namespaces: Namespaces are so similar to attributes but the concept of namespaces is one that transcends any particular programming language.There is a built-in function dir() that can be used to help one understand the concept of namespaces. This function list the objects in the current (or default) namespace. This function can also be used to show the names available within a module namespace. Namespaces are a simple concept. A namespace is a place in which a name resides. Each name within a namespace is distinct from names outside of the namespace. This layering of namespaces is called scope. A name is placed within a namespace when that name is given a value. The names in the namespace can be called using the dot. Namespaces can be imported using import command. Namespaces are similar to packages in java programming language


No comments:

Post a Comment