Answer the question
In order to leave comments, you need to log in
How do objects interact in Python?
Good day, hard workers!
How can I not grasp the essence of how objects communicate with each other in Python? Here, for example in Java, I understand an example:
import java.util.Scanner;
//Создаем класс
public class Converter {
//точка входа
public static void main(String[] args) {
Converter c = new Converter();//создаем экземпляр класса
User u = new User(); //создаем экземпляр класса
int CTemp = c.getScan(); //получаем значение
u.setCTemp(CTemp); //устанавливаем значение переменой экземпляра
int C = u.getCTemp();//получаем значение
float F = (9/5) * C + 32; //получаем результат
System.out.println("C to F = " + F);//вызываем метод объекта System
}
public int getScan() {
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
System.out.print("Put the C temprature: ");
int tmp = scan.nextInt();
return tmp;
}
}
public class User {.
private int cTemp;//переменная экземпляра
public void setCTemp(int temp) {//устанавливаем значение переменной
cTemp = temp;
}
public int getCTemp() {//возвращаем значение
return cTemp;
}
}
Answer the question
In order to leave comments, you need to log in
OOP in Python is not fundamentally different from OOP in Java.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question