Python 3 Tutorial for Beginners #16 - Classes

preview_player
Показать описание
Hey ninjas, in this Python 3 tutorial we'll take a look at classes, and how we can use them to create out own data types.

----- COURSE LINKS:

---------------------------------------------------------------------------------------------
Other tutorials:

----- NODE.JS TUTORIALS

============== The Net Ninja =====================

================== Social Links ==================

Рекомендации по теме
Комментарии
Автор

Only in that case it is running
class Bank(object):
def __init__(self):
self.name='Alalhabad Bank'

self.location='Kolkata'
self.business=5.56

class Bank:



bnk= Bank()
print(f'Name of the bank is : {bnk.name} and Total Deposit of the bank is : {bnk.deposit}')

sidaxn
Автор

Thanks for th video I have to agree with johnpro2. I can google probably what method, class are and why we need it, like an example why we may need it and when regular def won't be as useful as class, but it would be nice if you explained why we need it and what it does.

elmirach
Автор

@ 1:50 problem ..how many people know what is a blueprint.? I prefer the definition: Class is a combination of functions & variables. Thanks for the series.

johnpro
Автор

4:37 m/(s^2) not m/s, great video shaun ;)

alexmason
Автор

Thanks. And "self" is used to access both instance and class variables?

zt.
Автор

Keep getting an error with def__init__(self):. says its an invalid syntax. Any help?

DanmanJR
Автор

I think this way is much cleaner:
class Planet:

def __init__(self, name, radius, gravity, system):
self.name = name
self.radius = radius
self.gravity = gravity
self.system = system
def orbit(self):
return f'{self.name} is orbiting in the {self.system} with a radius of {self.radius} and gravity of {self.gravity}'


hoth = Planet('Hoth', 5.5, 'Hoth System')

print('Planet stats: ')
print(f'Name: {hoth.name}')
print(f'System: {hoth.system}')
print(hoth.orbit())

ecerejo
Автор

the word "self" is a convention or a reserved word in python?

simonhuang
Автор

I have this problem
Name is: Hoth
Radius is:
the gravity is: 5.5
Traceback (most recent call last):
File "classes.py", line 17, in <module>
print(hoth.orbit)
AttributeError: 'Planet' object has no attribute 'orbit'
the code is copied from the video, but not work, how it worked?

tommasoscasseddu
Автор

Using python 3.8.0 and I am getting an error. It's not printing the variables contents.



Name is: {hoth.name}
Traceback (most recent call last):
File "New.py", line 18, in <module>
print({hoth.name})

AttributeError: 'Planet' object has no attribute 'name'


Below is the code i


class Planet:
def __int__(self):
self.name = 'Hoth'
self.radius =
self.gravity = 5.5
self.system = 'Hoth System'

hoth = Planet()
print(f'Name is: {hoth.name}')
print({hoth.name})
print(f'Radius is: {hoth.radius}')
print(f'the gravity is: {hoth.gravity}')

TheSuccumbedSilence
Автор

Self is like this in other programming languages?

Bissimp
Автор

i really have a difficulty to understand the examples when doing maths :(

bataniyehram
Автор

it's always difficult for me to understand classes. What can i do?

abdallahdataguy
Автор

@1:49 was that coming out the rear or the mouth? :D :D :D Thank you SO MUCH for these videos! Audio volume is better in this one.

Tay-kyfi
Автор

In my case error is coming class is not defined.

sidaxn
Автор

I followed the tutorial.. but got this

Name is: Hoth
Radius is
the gravity is 5.5
<bound method Planet.orbit of <__main__.Planet object at 0x0105FF30>>

using:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32

Tay-kyfi
Автор

I don't understand why all languages start teaching with numbers, strings, lists, arrays and data types, when starting with objects and classes make all the sense in the world. Not that I'm blaming this author, I have always found it ridiculous to think of programming - having objects and classes obscured behind 15 or so chapters and constant babbling about data types, their properties, functions and methods. All the books and documentations defer objects and classes till it gets boring. Well, why not start with objects and classes to start with and specialize into data types and their props and methods subsequently?? That is just so in harmony with the natural world. So exciting to create objects just like in real world and think of everything like so.

beosoftlabs