Python object-oriented

Python object-oriented

Python is an interpreted language, it means that commands are executed through a piece of software by the Python interpreter.

Python is also an object-oriented language, and classes form the basis for all the data types of the language. Having in mind this point of view, we need to consider everything on python as an object, including the traditional primitives of other languages. In the following table we show a list of the built-in classes for Python.

Each one of those types allows to create an object: In the traditional way and as an object. For example:

Ways to define an Integer x with value 5:

x = 5

x= int(5)

x= int('5')

The first option is the most common, the second is not used frequently and just shows how the constructor can receive the value, and the third one is used very often to cast a a value that comes as a string.

Similar approaches are followed for the other types, and works in different ways, but if unsupported value is provided to the constructor, you would get a Value error exception.

Calling Methods

If everything is an object on python, it also means that every object has built-in methods and It's possible to use it following the standard dot notation for objects:

object.method(arg1, arg2...)

For example, the string objects have a lot of methods that we can use for our convenience:

my_str = 'Andres'

my_str.lower() // andres

my_str.upper() //ANDRES

Each one of the examples above, return a new object with modified value of the original. It means that you can apply another method to the returned object in cascade. For example:

my_str = my_str.lower().startswith('a') // True

This is just an introduction, even so with these small examples you can see how powerful is Python and for you are invited to explore all the methods provided by the different types of objects.

If you want to know more about python, the resource is https://www.python.org/

Also, there is a recommended article: 5 reasons to learn python

Happy coding!

Andres, thanks for sharing! 👌

Like
Reply

To view or add a comment, sign in

More articles by Andres G.

  • Qué pérdida de tiempo la filosofía

    Si le preguntas a alguien con "bastantes estudios" qué piensa sobre la filosofía, es probable que te diga que no tiene…

  • El balance necesario para trabajar en tecnología

    Hola, soy Andrés González, apasionado por la tecnología desde siempre. Aunque actualmente ya no programo tanto como…

  • A Letter from PHP to Developers

    Dear Developer, It’s me, PHP. Yes, that PHP, the language you like to laugh about on meetups.

  • Let’s talk about AI finally

    I've been avoiding this topic—not because it isn't important, but because it's not new. AI has been quietly…

    2 Comments
  • Is Django the best solution for a simple one page website?

    Well, the initial answer would be NO. And some of the very valid reasons are: I should not have to configure a…

    15 Comments

Others also viewed

Explore content categories