Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Convert Types | Reunindo todos os tópicos
Tipos de Dados em Python

Deslize para mostrar o menu

book
Convert Types

At times, Python may automatically assign a data type to a variable, which might not align with our intended choice. Hence, it is advantageous to possess the capability to exert control over the data type selection.

For instance, we can turn a number into a string, change the type of numerical data, or even use whichever number as a boolean data type. In this chapter, we are going to take care of converting numerical data types.

First and foremost, take a look at the syntax of converting a number to the integer data type:

1234567
value1 = int(657.89) value2 = int(90e3) value3 = int("678") print(value1) print(value2) print(value3)
copy

Note

It has a simple syntax, int(number), but if we want to convert a string to an integer, this string should contain integer numbers in quotes, like int("8990"), not int("899.0").

Tarefa

Swipe to start coding

You're working on an application that receives readings from three different sensors: temperature, altitude, and pressure. All sensors return float values, but your database only accepts integers.

  1. Use the int() function to convert each reading into an integer.
    • Convert temperature_celsius into integer1.
    • Convert altitude_meters into integer2.
    • Convert pressure_pascal into integer3.
  2. Each resulting variable must be of type int.
  3. Store the final results in the variables integer1, integer2, and integer3.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 1
Sentimos muito que algo saiu errado. O que aconteceu?

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

book
Convert Types

At times, Python may automatically assign a data type to a variable, which might not align with our intended choice. Hence, it is advantageous to possess the capability to exert control over the data type selection.

For instance, we can turn a number into a string, change the type of numerical data, or even use whichever number as a boolean data type. In this chapter, we are going to take care of converting numerical data types.

First and foremost, take a look at the syntax of converting a number to the integer data type:

1234567
value1 = int(657.89) value2 = int(90e3) value3 = int("678") print(value1) print(value2) print(value3)
copy

Note

It has a simple syntax, int(number), but if we want to convert a string to an integer, this string should contain integer numbers in quotes, like int("8990"), not int("899.0").

Tarefa

Swipe to start coding

You're working on an application that receives readings from three different sensors: temperature, altitude, and pressure. All sensors return float values, but your database only accepts integers.

  1. Use the int() function to convert each reading into an integer.
    • Convert temperature_celsius into integer1.
    • Convert altitude_meters into integer2.
    • Convert pressure_pascal into integer3.
  2. Each resulting variable must be of type int.
  3. Store the final results in the variables integer1, integer2, and integer3.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 1
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt