Monthly Archives: October 2021

VARIABLES AND ATTRIBUTES IN PYTHON

OBJECTS IN PYTHON Let's start by talking about the topic "Objects variables and attributes in Python". The most important concept to learn to understand the architecture of the entire Python programming language is that in this language everything is an object. The programs that we for example write in the schell as a series of instructions are also objects. It is essential to understand that Python assigns to all these entities, when the program is executed, data structures that are called objects. Objects in Python as already mentioned are data structures that at least contain: An identifier assigned by [...]

By |2024-08-09T19:33:12+02:001 October 2021|0 Comments

BASIC DATA TYPES IN PYTHON

TYPES OF DATA IN PYTHON NUMERICAL TYPES Let's start talking about Basic Data Types in Python by introducing the numeric types which are divided into: Integer Floating-Point Boolean It is important to know that all numeric types in Python are immutable, once a number is created and therefore an object it cannot change. For example, I can create a variable a that first points to an object worth 3 then to an object worth 4. What you can't do is change the value of the object, the number 3 is always the number 3. type=int int is the integer [...]

By |2022-10-18T18:23:30+02:008 October 2021|0 Comments

THE LISTS IN PYTHON

DATA STRUCTURES Before talking about the topic Lists in Python let's make a brief introduction to the data structures in Python which are composed of: Lists Tuple Dictionaries Set They allow you to keep not a single value as in Basic Data Types but a set of values called elements. Lists and tuples can contain elements of any type. Lists are mutable Tuples are immutable For example, a list can contain different elements, integers, strings, other lists. However, it is better to avoid non-heterogeneous elements, this to improve the readability of the program. The lists are [...]

By |2021-11-17T10:33:59+01:0012 October 2021|0 Comments

TUPLE, DICTIONARIES AND SETS IN PYTHON

THE TUPLE Let's start talking about the topic "Tuple dictionaries and sets in Python". We have four types of objects, tuples and lists which are simple assorted items, dictionaries which are key-value pairs, and sets which resemble the classic sets we know from mathematics. Let's see them in detail. type = tuple Tuples are a sequence like lists, but unlike lists, a tuple is immutable. This means that once the values that may be heterogeneous have been entered and initialized, they are no longer editable. All tuples are instances of a predefined type which is called a tuple. From [...]

By |2024-08-10T14:22:57+02:0015 October 2021|0 Comments

CONDITIONAL STRUCTURES, CYCLES AND RANGE IN PYTHON

CODE STRUCTURES LINES OF CODE Before we talk about "loop and range conditional structures in Python", let's look at code structures. The physical line is the line of code we write. The logical line is the one that Python assembles from a certain number of physical lines and then generates a single instruction. Let's see an example. The simple program shown here makes use of two lines of code and a comment that is not part of them. When Python runs the program it transforms the two lines of code into two [...]

By |2022-10-24T15:41:20+02:0017 October 2021|0 Comments

THE FUNCTIONS IN PYTHON

Before analyzing the functions in Python let's talk about another important aspect of the language, namely the List Comprehensions, the Dict Comprehensions and the Set Comprehensions. LIST COMPREHENSION It is a mechanism that starting from a list or any iterable object produces another in a single instruction by performing sophisticated processing starting from the source list. The central part of this statement should be familiar, it is a for in loop that iterates through the collection placed in iterable and each extracted element places it in the variable item. To the right appears a conditional structure if [...]

By |2024-08-11T02:57:10+02:0021 October 2021|0 Comments

FUNCTION OBJECTS AND NAMESPACE IN PYTHON

USE OBJECTS FUNCTION Before addressing the topic "Namespaces in Python" let's have a few more thoughts on functions. If we use the round brackets after the function it means that we are calling the function, if we use only the name of the function in the program it means that we are referring to the function as an object whose instance belongs to the function class. This means that functions are objects and are instances of the function class. Let's see what the main features are in using functions as objects. Nested functions Let's [...]

By |2024-08-11T05:10:55+02:0023 October 2021|0 Comments

CLASSES IN PYTHON

CLASSES AND INSTANCES Class objects generally provide the default behavior, they contain a series of attributes which are then data and functions that in the OOP context are called methods. The instances are created, instantiated, starting from the classes and carry out the activities within the programs that we write in Python. THE STATEMENT CLASS The class statement is a compound statement that serves to define and create a class object by assigning a name to it. When Python finds the keyword class within a source, which obviously has a header and a suite of instructions, it executes it [...]

By |2024-08-12T01:55:35+02:0024 October 2021|0 Comments

INHERITANCE IN PYTHON

INHERITANCE The first thing to say about inheritance in Python is that the language allows one class to inherit the attributes and methods of another class. Subclasses or derived classes that are the most specialized inherit attributes and methods from their base classes or superclasses. Derived classes can override the behavior of inherited attributes (methods) and can add additional functionality that tends to specialize the class. Superclasses are generally more generic than their subclasses. When we create an instance of a subclass, this is also an instance of all the superclasses of the class of which it is an [...]

By |2024-08-12T10:53:43+02:0026 October 2021|0 Comments

THE EXCEPTIONS IN PYTHON

THE EXCEPTIONS IN PYTHON Let's start with an example regarding the exceptions in Python. The function divides the first parameter by the second and returns its value. If we pass a zero as the second parameter, we get an exception as Python is unable to divide by zero. It is said that an exception is raised by the Python runtime and the program crashes. THE HIERARCHY OF CALLS What occurs when an exception is raised is shown in the figure alongside. If the exception is raised in function f4(m, n) and is not handled, Python goes [...]

By |2022-10-24T23:48:12+02:0031 October 2021|0 Comments
Go to Top