
When coding with Python we realize that the fundamental idea is creating objects and apply operations (addition, concatenation, etc) on those objects. Objects are essentially pieces of memory with some data and operations associated with them, objects can be built-in by default in Python or they can be created using Python or other languages tools.
In a broader perspective, Python programs can be broken down into modules, statements, expressions, and objects. Thus a Python program contains at least one module, which in times contains statements that are built with expressions and those expressions create and process objects.
In lower level languages, implementing data structures, managing memory allocation, implement search and access routines, and so on, are really time-consuming tasks. Python provides a powerful set of built-in objects. Thus, coding objects implementations is not necessary unless some special properties are required.
Let's review some advantages of using built-in objects:
Numbers in Python range from integers (those without fractional part), floating-points numbers (numbers with a decimal point in them), and some more complex types (fixed-precision decimals -pi, e, etc; rational fractions, complex numbers with imaginary parts, and some more).
Ordinary mathematical operations are supported as well. The plus sign (+) performs addition, a start (*) is used for multiplication, two stars are used for exponentiation (**). For now, this will suffice to describe this object type, more advanced tools are available by importing some modules shipped with Python or using third-party modules. Since their application is more specific, they will be covered in other posts.
Strings are a positionally ordered collection of bytes generally used to record textual information or some other random data. They are the simplest versions of an array of one-character string called which are called Sequences.
Strings support operations that involve positional ordering between elements. Let's review some examples:
>>> S = "string" >>> len(S) # This will show the length of the string 6 >>> S[0] # This will show the first element of the string from left to right "s" >>> S[3] # This will show the fourth element of the string from left to right "i" >>> S[-1] # This will show the first element of the string from right to left "g"
The first position is enumerated with the number 0. Also, negative indexes are added to the string size, and the element on that position is then printed. One of the cool features of Python is that its syntax is really general. If a function is expecting us to input some value, we could use a literal, a variable, or any other equivalent expression. For instance, we can fetch the last item of a string in the above example by typing either of the following expressions.
>>> S = "string" >>> S[-1] "g" >>> S[len(S)-1] "g"
|
Basic Concepts. Part 1 Whaleshares Link Steemit Link |
Basic Concepts. Part 2 Whaleshares Link Steemit Link |
Program designing. Part 3 Whaleshares Link Steemit Link |
|
Program designing. Part 4 Whaleshares Link Steemit Link |
