Python language basics 77: class property getters

Introduction

In the previous post we looked at a special group of class level methods called setters. We saw that they were really not different from other class level methods. The single major difference lies in the purpose of setters, which is to let external users of a class provide a value for a class property. We also discussed that a setter may not be available for immutable, read-only or otherwise complex class properties.

In this post we’ll look at the counterpart of setters called getters.

Read more of this post

Python language basics 76: class property setters

Introduction

In the previous post we looked at class level methods. We saw that they weren’t much different from “normal” methods. The fact that the first input parameter is “self” is what differentiates class level methods. Also, they can be called on an instance of a class, i.e. an instantiated object. The extra properties that the method needs are provided after “self”.

In this post we’ll look at a special group of class methods: setters.

Read more of this post

Python language basics 75: class level methods

Introduction

In the previous post we looked at the basics of validation. In particular we looked at an example where the values sent to the initialiser were validated in code. Validation is important in order to stop invalid values being assigned to class level variables. However, validation can occur just about anywhere in code. E.g. if a numeric input is required from the user then you’d almost certainly need to validate it so that the code doesn’t stop with an exception when trying to convert the string input into a number.

In this post we’ll quickly look at class level methods.

Read more of this post

Python language basics 74: validating class level properties

Introduction

In the previous post we discussed class level properties in some detail. The most important detail we learned is that there are only public members in a Python class. Properties can be added to “self” on the fly within the class but those properties will be visible to all external callers. So all you’ve learnt about access modifiers from your Java course, such as private or public is not applicable in Python.

In this post we’ll explore the basics of validating the values that are sent into the object initialiser. Validation is a large topic so consider this only as a light introduction.

Read more of this post

Python language basics 73: class level properties

Introduction

In the previous post we looked at initializers and class level properties. We saw how to add the init method to a class so that we could provide the name property. We also added a second init method so that we could still have an “empty” Person object with no preset name. We also discussed how to attach class level fields to “self” on the fly. The value assigned to those properties was available from another class level method.

In this post we’ll consider class level properties. I felt it was important to provide a post dedicated to that topic because the behaviour of class properties in Python is markedly different from other popular OOP languages such as Java, C#, C++ or VB.NET. At least I was quite surprised when I was first exposed to these class related details in Python.

Read more of this post

Python language basics 72: object initializers and class level properties

Introduction

We continued to explore the notion of classes in the previous post. We looked at the difference between constructors and initializers although we haven’t seen the initialisers in action yet. We also built our first class called Person that had one class method called shout. The shout method could be called on an instance of the Person class, i.e. a Person object using the standard dot notation.

In this post we’ll look at the role of initializers and how to supply method arguments to class methods.

Read more of this post

Python language basics 71: continuing with classes

Introduction

In the previous post we started discussing classes. We said that classes are the models for objects. The objects are instantiated based on the classes. A class describes the properties for the objects. E.g. a Car class can have a number of variables, such as colour, make, etc. A class can not only contain simple properties, but methods as well, as we’ll see later. Also, a class controls how an object can be instantiated.

Read more of this post

Python language basics 70: starting with classes

Introduction

In the previous post we extended the topic of comprehensions and looked at comprehension filters. We saw that it was really easy to extend the standard comprehension “formula” with an if-clause. The filter is then applied to every element in the iteration and the comprehension function only considers those elements that pass the boolean test.

In this post we’ll start looking at something completely different: classes. Classes are probably the most important building blocks of object oriented languages.

Read more of this post

Python language basics 69: filtering comprehensions

Introduction

In the previous post we discussed how to iterate over a dictionary with the concise comprehension syntax. We saw that it wasn’t very different from how list comprehensions are written.

In this post we’ll look at how to attach a conditional clause to a comprehension function.

Read more of this post

Python language basics 68: iterating over a dictionary with dictionary comprehension in Python

Introduction

In the previous post we looked at a Python language construct called comprehension. We saw that comprehensions are a very concise way of iterating over a collection, applying a function to each element and adding the resulting element to a new collection. All that is declared in a single comprehension statement.

In this post we’ll look at dictionary comprehensions.

Read more of this post

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: