Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Numbers | Common data types
Learn Python from Scratch
course content

Contenido del Curso

Learn Python from Scratch

Learn Python from Scratch

1. The basics
2. Arithmetic operations
3. Common data types
4. Conditional statements
5. Other data types
6. Loops
7. Functions

bookNumbers

As you may notice, despite having two integer numbers, Python somehow classified them with different types: one of them is int, while another is float. Also, there is one more numeric type in Python. Let's consider all of them:

  • int - refers to integer numbers (i.e. 3, -1, 1003 etc);
  • float - refers to real numbers (i.e. 2.8, 3.333, 3.0 etc);
  • complex - refers to complex numbers (i.e. 3+2j).

To make Python understand that you want to assign to a variable specific type, use int() for converting to an integer, float() - to real, complex() - to complex.

Returning to our question above, Python assigned float type to variable days as it wants to "play it safe", insofar as the division of two integers is not a compulsory integer (unlike multiplication, subtraction, or addition).

Tarea

The distance between San Francisco and New York is about 4677.4 km (by roads). This value is saved in dist_km variable. Your tasks are:

  1. Convert the distance to miles by diving distance in kilometers by 1.609 (approximately). Save the result within dist_mi variable.
  2. Output the value of dist_mi.
  3. Convert dist_mi into integer, and output this value.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
toggle bottom row

bookNumbers

As you may notice, despite having two integer numbers, Python somehow classified them with different types: one of them is int, while another is float. Also, there is one more numeric type in Python. Let's consider all of them:

  • int - refers to integer numbers (i.e. 3, -1, 1003 etc);
  • float - refers to real numbers (i.e. 2.8, 3.333, 3.0 etc);
  • complex - refers to complex numbers (i.e. 3+2j).

To make Python understand that you want to assign to a variable specific type, use int() for converting to an integer, float() - to real, complex() - to complex.

Returning to our question above, Python assigned float type to variable days as it wants to "play it safe", insofar as the division of two integers is not a compulsory integer (unlike multiplication, subtraction, or addition).

Tarea

The distance between San Francisco and New York is about 4677.4 km (by roads). This value is saved in dist_km variable. Your tasks are:

  1. Convert the distance to miles by diving distance in kilometers by 1.609 (approximately). Save the result within dist_mi variable.
  2. Output the value of dist_mi.
  3. Convert dist_mi into integer, and output this value.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
toggle bottom row

bookNumbers

As you may notice, despite having two integer numbers, Python somehow classified them with different types: one of them is int, while another is float. Also, there is one more numeric type in Python. Let's consider all of them:

  • int - refers to integer numbers (i.e. 3, -1, 1003 etc);
  • float - refers to real numbers (i.e. 2.8, 3.333, 3.0 etc);
  • complex - refers to complex numbers (i.e. 3+2j).

To make Python understand that you want to assign to a variable specific type, use int() for converting to an integer, float() - to real, complex() - to complex.

Returning to our question above, Python assigned float type to variable days as it wants to "play it safe", insofar as the division of two integers is not a compulsory integer (unlike multiplication, subtraction, or addition).

Tarea

The distance between San Francisco and New York is about 4677.4 km (by roads). This value is saved in dist_km variable. Your tasks are:

  1. Convert the distance to miles by diving distance in kilometers by 1.609 (approximately). Save the result within dist_mi variable.
  2. Output the value of dist_mi.
  3. Convert dist_mi into integer, and output this value.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

As you may notice, despite having two integer numbers, Python somehow classified them with different types: one of them is int, while another is float. Also, there is one more numeric type in Python. Let's consider all of them:

  • int - refers to integer numbers (i.e. 3, -1, 1003 etc);
  • float - refers to real numbers (i.e. 2.8, 3.333, 3.0 etc);
  • complex - refers to complex numbers (i.e. 3+2j).

To make Python understand that you want to assign to a variable specific type, use int() for converting to an integer, float() - to real, complex() - to complex.

Returning to our question above, Python assigned float type to variable days as it wants to "play it safe", insofar as the division of two integers is not a compulsory integer (unlike multiplication, subtraction, or addition).

Tarea

The distance between San Francisco and New York is about 4677.4 km (by roads). This value is saved in dist_km variable. Your tasks are:

  1. Convert the distance to miles by diving distance in kilometers by 1.609 (approximately). Save the result within dist_mi variable.
  2. Output the value of dist_mi.
  3. Convert dist_mi into integer, and output this value.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 3. Capítulo 2
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt