Learning Python: Objects

As stated in a previous blog post, all data types in Python are objects. Objects are composed of methods and attributes. In Python these are accessed using dot ..

Examples

We print out the real part of the number since now num is now an object and has access to the methods for objects of type int.

num = 1
print(num.real) #1

If we create

mylist = [2,4]
mylist.append(6) #[2,4,6]

An important rule to understand is the memory address of a variable will change if you assign it a value that is different. If you use one of the variable's built-in methods in order to modify it, then the memory address remains the same.

This blog post was originally published on my blog Communicode, where I write about different tech topics.

Python
Avatar for Muhammad Asfour

Written by Muhammad Asfour

I am a Full Stack Developer with over 5 years of experience. I have worked with different tech stacks such as: Groovy/Java, PHP, .NET/.NET Core (C#), Node.js, React, Angular, and Vue.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.