M
M
Magic Code2019-11-19 17:40:55
Python
Magic Code, 2019-11-19 17:40:55

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;
  }
}

Objects communicate with each other through methods and instance variables. I understand the principle of interaction between objects. And in python, how does the interaction of classes and objects work? Thanks in advance for the example and the answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-11-19
@Panda_Code

OOP in Python is not fundamentally different from OOP in Java.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question