EC Lecture Notes - Lecture 8: Init, Mecha, Class Variable

4 views2 pages

Document Summary

An instance or non-static variables are different for different objects (every object has a copy). The class may have a static variable whose value is cse for all objects. And class may also have non-static members like name and roll. In c++ and java, we can use static keywords to make a variable a class variable. The variables which don"t have a preceding static keyword are instance variables. See this for java example and this for c++ example. The python approach is simple; it doesn"t require a static keyword. All variables which are assigned a value in the class declaration are class variables. And variables that are assigned values inside methods are instance variables. # python program to show that the variables with a value. # assigned in class declaration, are class variables. # class for computer science student class csstudent: stream = "cse" def __init__(self,name,roll): # class variable self. name = name self. roll = roll.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents