+ 1
I didnt understand classes in python??? Plz help
2 Réponses
+ 1
if you are talking about the conception i cannot help you.But if you want to know what is class it is simply used to create objects which are similar to each other
+ 1
example on C++:
class Human{
//Creating the properies of the class
string name;
int age;
//constructor of the class
Human(string name,int age){
this->name=name;
this->age=age;
}
//method of the class (the class can have as many methods as you want such as the propeties)
void sayHello(){
cout<<"Hello my name is "<<this->name<<" !"<<"\n";
cout<<"And I am "<<this->age<<" years old !"<<"\n";
}
}
int main(){
Human student1=Human("Johny",14);
Human student2=Human("Susan",16);
student1.sayHello();
student2.sayHello();
return 0;
}
output:
"Hello my name is Johny and I am 14 years old"
"Hello my name is Susan and I am 16 years old"
so classes can be used in many programs to make objects and to short your code