Q:

PySerial Arduino receives data incorrectly

The code that I've written is supposed to send the string "1" to the Arduino. Instead, from what I can see it receives "49" and for that reason both of the IF statements do not work. What am I doing wrong? I am using a Macbook(Mojave).
Here's the Arduino code:
String data;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Serial.println(1);
  digitalWrite(13, LOW);
}

void loop() {
  while (Serial.available()) {
      data = Serial.read();
      Serial.println(data);

      if (data == "1") {
          digitalWrite(LED_BUILTIN, HIGH);
          Serial.println("ON");
        } else if (data == "2") {
          digitalWrite(LED_BUILTIN, LOW);
          Serial.println("OFF");
        }

    }
}

And here's the python3 code:
import serial
import time

ArduinoSerial = serial.Serial('/dev/tty.usbserial-AH06F2WM', 9600)
time.sleep(2)

ArdData = ArduinoSerial.readline().decode('ascii')
print(ArdData)

ArduinoSerial.write("1".encode())

ArdData = ArduinoSerial.readline().decode('ascii')
print(ArdData)

Thank You!

A:

In the ASCII table, a decimal value of 49 represents char '1'. 
String and char are different. Serial.read() does not return a String. It returns an int. 
You can use Serial.read() and treat a returned value as a char. Change String data to char data and compare against a char in the if statements.
char data; // char

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Serial.println(1);
  digitalWrite(13, LOW);
}

void loop() {
  while (Serial.available()) {
      data = Serial.read();
      Serial.println(data);

      if (data == '1') {  // <- '1', not "1"
          digitalWrite(LED_BUILTIN, HIGH);
          Serial.println("ON");
        } else if (data == '2') {  // <- '2', not "2"
          digitalWrite(LED_BUILTIN, LOW);
          Serial.println("OFF");
        }

    }
}

Or, if you really want to use String, you should use Serial.readString() instead.
String data;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Serial.println(1);
  digitalWrite(13, LOW);
}

void loop() {
  while (Serial.available()) {
      data = Serial.readString(); // <- readString() not read()
      Serial.println(data);

      if (data == "1") {
          digitalWrite(LED_BUILTIN, HIGH);
          Serial.println("ON");
        } else if (data == "2") {
          digitalWrite(LED_BUILTIN, LOW);
          Serial.println("OFF");
        }

    }
}

