#52 Python Tutorial for Beginners | Types of Variables
HTML-код
- Опубликовано: 27 ноя 2024
- Python Tutorial to learn Python programming with examples
Complete Python Tutorial for Beginners Playlist : • #1 Python Tutorial for...
Python Tutorial in Hindi : • #1 Python Tutorial | I...
Github :- github.com/nav...
Check out our courses:
Spring Framework in 8 Full Day Course Live: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Complete Java Developer Course Batch-3: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
Udemy Courses:
Spring: go.telusko.com...
Java:- go.telusko.com...
Java Spring:- go.telusko.com...
Java For Programmers:- go.telusko.com...
Python : go.telusko.com...
Git : go.telusko.com...
Docker : go.telusko.com...
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : www.youtube.co....
Telusko Hindi :
www.youtube.co....
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
www.telusko.com...
This is exactly called Teaching.
Give him an award.🏆
Do you know why he didn't gave you a like 😂
Because the caption of this channel is *we don't teach we educate*
😂
@@crickettrendzz5477 he is tuting..
Animations are very effectively used !!!
world class instructor
You are a great teacher. Keep it up please
Sir now your videos are much better bcz you are teaching programming not programming languages.. which is very rare 🙏🙏🙏..
Good audio quality
Good graphics
Good explanation skills
😉 These are the things that many videos in the youtube lack
And hence they are inconvenient
But welcome to telusko learnings where these are satisfied
bruh
ive seen many much better edits and graphics and explaining. also ive seen way better audio
Give lot of salary to your graphic designer..its amazing😀😀
civil engineer learning python..:) :).. thanks for making it interesting and simple..
@@perfectrahul495 Here mechanical engineer bro.
@@anindian4601 same here brother
@@akashk7507 😊 nice to hear bro
@@anindian4601 BTW you are from tamilnadu I guess
@@akashk7507 No bro
Sir Thanks for the python tutorial series :)I am started learning python from your series You are the best sir.
I used
c1.wheels=10
And it affected only c1.wheels, not c2.wheels and car.wheels...
After, If we use car.wheels=5, it affects car.wheel and c2.wheels and not c1.wheels
When i use c2.wheel=30, it affects only c2.wheels,... This means it creates new space when changing values specifying object name like c1.wheels and c2.wheels
I think I've worked it out. When you do, c1.wheels = 5 you are declaring a new variable for the object (it just happens to have the same name as the class variable) and signing it '5'. If you output it's 'id'...print(id(c1.wheels))... it will be different to c2.wheels and Car.wheels. (c2.wheels and Car.wheels will have the same id)
Instead of doing that, try this
classname.attribute = value
i think you will get it
because it way of declaration if you calling class and storing that in to a variable then if you do any change with that variable then it will effect only that variable class not every variable where the class is calling
We have two types of variables
1. Class variables or Static variables - (e.g. wheels) - which are stored in the class namespace
2. Instance variables - (e.g. com, mil) - which are stored in instance namespace
Hi Navin,
This class and instance variable is very much clear. But can u please explain me the below code and it is working fine also.
class car():
wheel = 4
def __init__(self):
self.mil=10
self.name="BMW"
c1=car()
c2=car()
c1.wheel=5
print(c1.mil,c1.name,c1.wheel)
print(c2.mil,c2.name,c2.wheel)
Output:
10 BMW 5
10 BMW 4
I too got this doubt
Congrats for being 1M+ Subscribers.... This is the proof of your quality teaching. Keep it up. Thanks a lot...💖💖💖💖
the more videos i watch the more amazed i get thank you so much sir
Well Explained Mr. Navin. And as usual :).
May be worth also, explaining the importance of "modifying class variables with class names only" and contrasting the effect of "modifying class variables with object names".
Here you go 🏆
Instance variable can only change the value of wheels for themselves whereas class can change for all of them
This right side explanation makes it more clear and easy to understand
Your content and way of teaching is really amazing,your the best teacher I have seen till now in terms of programming,A BIG THANK YOU!✨
u are the best teacher ever
Best teacher of Universe 🥇
Huge respect, sir even if you make an army, i would be one of the loyal soldiers, because we will never lose a battle with a commander like you. 🌍
when is change class variable with c1.wheels =5 . It only changes for c1 not for the c2. I thought static variable would change the value for all the objects even if we modify class variable with objects
This is the video I've been looking for a long time, Thanks Sir
Thank you for short and crystal clear explanation!
wow , navin sir you have got a huge fanbase , no dislikes on this video at all
Starting Music is good, loved it
sir
thank you very much for your effort
i was very new to these
since your explanation is very clear, i am able to understand very easily
i am very happy that you are teaching these for free
Thank you so much for making this topic so simple and easy.🙏
What a teacher he is it just amazing
hi sir, hope you are doing good and staying fit and healthy. I really love your teaching . I have a question. Here I am accessing the static variable outside the class using class name. But when I am trying to change the value of the static variable outside the class using object name it is changing the value of wheel for both the objects. For eg, c1=Car()
c2=Car()
c1.company='Toyota'
c2.wheels=7
print(c1.company,c1.mileage,c1.wheels)
print(c2.company,c2.mileage,c2.wheels)
This code should give error right ?!! but instead it is changing the value of wheel for the objects. Kindly clear out my confusion. Thank you sir and always stay blessed.
Hi Sayantan,
c2.wheels=7
will create a new "object variable" for c2 object.
It does not have anything to do with Car.wheels
Car.wheels is a separate "class-variable"
You can create n number of variables for any object. e.g.
c2.a=5
c2.b=8
c2.c=10
c2.wheels=7
All will create object variables for c2 with no link to class variable.
Now, when you print(c2.wheels) It will print the object variable wheels not the Car.wheels
Hope you Understand!!
Graphics in the video makes it very easier to understand
Really u r a legend ❤️❤️❤️❤️❤️❤️
legendary Sir ji
thank you so much omg this is perfect for understanding class/static variables in python!
thanks sir for teaching us in such a wonderful way
BEST TEACHER
you are a great teacher thank you keep going
Thanks for teaching about types of variable
Superb explanation Sir
Really good 👍
class Cars:
wheels = 4
def __init__(self):
self.mil = 10
self.com = "BMW"
c1=Cars()
c2=Cars()
c2.wheels=5
Cars.wheels=55
print(c1.wheels)
print(c2.wheels)
OUTPUT
55
5
EXPECTED OUTPUT
55
55
Please explain
I guess that when you access the wheels variable from the object so you will create new instance varible with the same name "wheels".
But when you access the wheels variable from the class name so you change the value of the static variable "wheels".
I just guess :D
i had the same issue.
Great constructor you Are sir😍🔥
Such a great tutor!
Simple and perfect explanation
HEYYYY Navin you are ossum.... thanks for each python video....
This sometimes happens with some cars hahah :D. PS. Your classes are the best !
Regards!
Naveen.....You are awesome....
Congrats for 1M subscribers
But c1.wheels=5 is also working.
hello sir
if u telling the particular topic pls tell us what are the applications abd few examples by using the topic
and we can undestand quickly about the topic and we can think about it
Hi Navin. What do you say ? Python should not let us change class variables data using object. And if so then, it should change for all existing objects, thats how meaningful concept of class variables comes into play. C++ has no instanced variables concept for this reason only. Abstraction should be same for all instances i.e. interface box should be same.
i don't know how can i express my love for this man😍😍😘😘😘😘
heyy chill man
Great sir ji 🤘
instead of defining compare can we use
if c1.age==c2.age & c1.name==c2.name
instead of
defining in compare with self and other argument?
master of python!!!!
I'm done with the series and waiting for the upcoming videos and please post them asap Naveen garu..thank you
Thank you so much for all your vedios, those are very useful. But im expecting theory notes from you. Practical part everything is fine.
How does namespace differ from heap memory? How do they fit together in the grander scheme of memory/space?
So good tutorial
Oh WOW...!!
Great sir Thanks a lot
thank you random indian man for letting me survive this years ict class
Thank You sir....❤️
but we can change the value of the class variable for an object
c1.wheels=3
print(c1.wheels) gives 3
print(c2.wheels) gives 4
because it way of declaration if you calling class and storing that in to a variable then if you do any change with that variable then it will effect only that variable class not every variable where the class is calling, so it will be limited to that variable only it will not effect globally
@@mohdibrahim1995then what's the difference between instance and class variables?
Sir, I have a doubt
at 4:34 in video
if i write c1.wheels=100, then value of "wheels" only change for c1 not c2, then why we will call it class variable but not instance variable.
yes, I tried that two it only affects only the referred objects property.
Instead of doing that, try this
classname.attribute = value
i think you will get it
because we are taking class as c1 and we are changing the value of c1 only but if you declare that in class_nameSpace then it will effect both c1 and c2 so if you change like ex: c2.whlees=25 it will show 25 for c2 not for c1 its area of declaration . try this
Even You can change Class variables using object.But It will affect variables of that object
Thank you.
Hi Navin , you are the best tutor . However from the OOP video onwards , I am a little lost and I know its because I am unable to relate , you are still superb. I come from a non technical back ground. Is there any other good reading material that you can refer me back to, just to understand the fundamental/basic of the OOP. Tried many other websites but no one is even close to you. So thought of checking with you directly
Thank you sir you are awesome
the best video
u r my CS god
Nice sir
Thank you sir
for i in range(1,100):
print("First class teacher in world")
I'd rather say while 1:
@@lokaabhiram771 yah bro that's right
Awesome 👍
Class/Static Variables = GLOBAL VARIABLES
Instance Variables = LOCAL VARIABLES.
Assign a new value to class variable like c1.wheels = 6, it behalves like instant variable, Please explain.
print(c1.wheels)
first it will check in c1 object , if not found it will check class level variable.
for print(c1.wheels) it worked fine, because there is no wheels variable in c1 object.
But when you write c1.wheels=6 it won't change the value of static variable, it simply creates a new variable in your c1 object. that's why you are getting different value.
c1.wheels=6 creates a new variable in c1 object with name wheels , So when you access you will get 6 rather than your static value.
Thanks
Hello Sir your explanation about each topic is so good, but I have a problem regarding class variable. I'm not defining any class variable inside a class but whenever I access it like
car.wheels = 3
print(car.wheels)
it's printing it..and I don't know why and how..
Interesting find. ...yes, I tried that and saw the same behaviour. Must be an advanced topic for another day😀
while x == 1
print('you are best')
x value need or else it will give you an error
And if we change the value for a instance variable using class name then the value for all the object variables changes
2:40 the main difference
so simple!!
Sir please tell us how did you edit your videos with such animation
Please sir
If possible then try to make a separate video on it. Its a humble request for your subscribers
i have a qs related to variables access specifier
should we use public instance variables or private ones then use getters and setters?
which approach is good in python?
What is local variable ??
c1.wheels also working without affecting c2. so how wheels is different from instance(milage).
When you change either of c1.wheels or c2.wheels, both the object will get effected. That does not happen in the case of c1.mileage.
@@BaapBaapBetaBeta no bro when i use c1.wheel =3 but my class.wheel=4 and i print(c1.wheel) then the output is 3 not 4 ,it means that c1 is also able to change the variable but c2 remains unaffected
Kaushal Jainer Techie Even i tried that ,then wheels might not be class variable, In java variable which is declared inside the class and outside method is instance variable and variable which is declared inside the method is local variable may be the same applies here too.
Do you people have paid/ advanced tutorials on Django or other python languages?
sir when we create a static variable and manipulate it by using object then what will happen internally? and shall it affects the another object of the same class?
it will not affect other objects of the same class. if you try to change the static var using instance then it will only create a new instance of that variable for the object. This will not affect the entire class.
At 4:26 , what if i put c1.wheels = 5 instead of car.wheels=5...????
Good sir
is there any software that can show output in the form of boxes like 1:08 in the video tutorial!
This question needs a reply
please reply
i fckn love you, thats the teaching
ye hamare sir h, ye unki car h ,aur ye hamari padhai ho rahi h
But actually there are three types of variables
1. Instance variable
2. Static(class variable)
3.Local variable
Mr.Navin how can i make a real projects with python , can you provide me websites that i can improve my skills
can we change the value of class variable for a particular object?
sir when we create a static variable and manipulate it by using object then what will happen internally? and shall it affects the another object of the same class? can you please explain that in some more details?
I wish he explained that aspect, like many others also noted. What I found out is that if you manipulate(change) a static variable(say, wheels = 4) by using object(say, car1.wheels = 5), that is entirely valid, but the value is effective only to the object(car1). It does not afect other objects. If you create an object (car2) later, then print(car2.wheels) will print 4 (the value defined by the static variable) not 5. That is why it is also termed "static variable" because it is static.
C1.wheels = 5(suppose)
It will make change only for c1 object.
If cars.wheels =5 will change for all object of that class...so how we can say that "wheels" is a "static" variable...and pls tell us what's happening behind the scenes ?
In class variable we can change the variable with both cases either by object name or by class name..if we change by class name it will change the entire wheels...if we change by object name it will change onu for that object wheel...and you cannot change mileage by class name as it is an instance variable...
Static is class variable right so it should not change by object value assignment