Python 3 Programming Tutorial - Classes

sentdex · Beginner ·🛠️ AI Tools & Apps ·12y ago

Key Takeaways

This video tutorial covers the basics of classes in Python 3, providing an introduction to understanding and using classes, with a practical example of creating a calculator class.

Full Transcript

Hello everybody and welcome to another Python 3 basics tutorial video. This video is going to be covering the basics of at least understanding classes in Python. For the most part, I just want you to understand how to like read and follow along with what's happening in someone else's class, not necessarily uh to teach you guys how to write really good classes and all that. The idea of class uh or classes is to kind of enase a group. It's almost like a uh a way you could use classes instead of modules. Um that's usually the way I see people using it is to save a almost like as if they were writing like scripts like like people do with Java, let's say. Um but they have classes and then underneath the classes they've got all their functions and it's just kind of treated as if class is equal to a module almost. But anyway, um I just want to show you guys how to follow them. class is really just a a way of grouping things together, I suppose. Um, but you can do some really neat things with classes and but actually I would kind of consider classes more of an intermediate kind of thing. Um, but I think at least understanding them is is good for basics. So uh with that, let's go ahead and get started. Uh, one of the simplest things I can think of to uh use as an example would be to create a class and make that class calculator. Um you don't have to put any parameters here just colon and that's it. So class calculator. So our calculator class uh should contain obviously some pretty simple uh things like what what does a calculator do? Well at its very basics a calculator should at least add, subtract, multiply and divide. Uh it should be able to do all those things. So we definitely want our calculator to be able to do that. So let's go ahead and do that. So uh for addition we'll say define addition. And for addition, we're just going to say we can only have two variables. So for addition, we have xy and we'll say added = x + y. And then we'll do print added. Okay, so that's our definition. Uh but now we also need this calculator to be able to do subtraction. So define subtraction and again xy. And now what we do is we'll say sub = x - y. Okay. Then we'll go ahead and print sub. Continuing right along, we also need to be be able to do multiplication. So define multiplication uh xy again colon. And now we'll say mult= x * y. Finally, we want to be able to do division. Define division uh xy colon and div equals x / by y and print div. Okay, so now we've got uh our basic calculator class, all the things that are uh encompassed within our class. And let me just uh push this up one little bit. And now let's say we actually wanted to use our class. So an example of someone using class would uh calculator. You would basically do the following. Calculator dot and let's say we wanted to do um multiplication calculator multiplication xy we want to do 35. So that would be how you call the multiplication division of multiplication division. thinking like division as in like a division of like a a company. Anyway, that's how you would do multiplication. Um within our calculator class. So, let's go ahead and save and run that. And oh, it just so happens we never printed out moles. Wow. Of all the ones that we didn't do. So, anyway, print molts. Okay, now let's run it. And sure enough, uh our multiplication gave us 15. Now, we can call the other ones. So, uh, calculator addition, uh, 52, uh, and that's going to give us a seven. Calculators subtraction, uh, 10 9, oops, 10 91. You guys get the idea. Um, so, uh, that's basically how you can kind of read and understand a class. Uh like I said, there's a some other things that people do with classes uh to get give them quite a bit of uh more functionality to them. But for now, uh these are just the kind of the basics of a class and how to understand like what people are doing uh when they use classes. So hopefully that was helpful for you guys. If you have any questions or comments, feel free to leave them in the uh comment section. As always, thanks for watching. Thanks for all the support and subscriptions. And until next

Original Description

Welcome to another Python 3 basics tutorial. This tutorial is going to be covering the basics of classes in python. For the most part, I just want you to just understand how to read and understand a class' workings. You can think of classes as groupings of functions, usually. Classes quickly work their way into "intermediate" programming, so hopefully I can just help you understand how they work and how to follow code that uses them. Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/ Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video tutorial introduces the basics of classes in Python 3, covering how to create and use a class, with a practical example of a calculator class. The tutorial aims to help viewers understand how to read and follow along with classes in Python.

Key Takeaways
  1. Create a new class in Python
  2. Define functions within the class
  3. Use the class to perform calculations
  4. Call functions from the class
  5. Print results from the class functions
💡 Classes in Python are a way of grouping functions and variables together, making it easier to organize and reuse code.

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →