Back to Browse

Python for Neuroimagers, Part 5: Classes

491 views
Jun 10, 2025
6:43

An overview of classes in Python, which are like templates which can create other objects with a list of properties and functions. This tutorial will show you how to create and modify your own classes and instances, as well as how to create methods that can be used by that class. Link to Chapter 5 of the Python for Neuroimagers tutorial of Andy's Brain Book: https://andysbrainbook.readthedocs.io/en/latest/PythonForNeuroimagers/Python_05_Classes.html Code used: class Brain: lobes = ['frontal', 'parietal', 'occipital', 'temporal'] def __init__(self, name, volume=1400): self.name = name self.volume = volume my_brain = Brain('andy') print(my_brain.name + "'s brain has a volume of" + str(my_brain.volume)) your_brain = Brain('susan', volume=1390) print(your_brain.name + "'s brain has a volume of" + str(your_brain.volume)) my_brain.lobes = ['frontal', 'parietal', 'occipital'] my_brain.lobes your_brain.lobes class Brain: lobes = ['frontal', 'parietal', 'occipital', 'temporal'] def __init__(self, name, volume=1400): self.name = name self.volume = volume def thinking(self, thinking='yes'): if thinking == 'yes': print("Congratulations, you are thinking!") elif thinking == 'no': print("You're not thinking right now; you are probably watching TV!") else: print("I'm not sure what you're doing!") Table of Contents ============== 0:00 What are Classes? 1:01 Creating a Class 3:00 Class and Instance Attributes (aka Properties) 5:22 Creating Methods 6:18 Summary

Download

0 formats

No download links available.

Python for Neuroimagers, Part 5: Classes | NatokHD