Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Convert Types | Поєднання всіх тем разом
Типи даних у Python
course content

Зміст курсу

Типи даних у Python

Типи даних у Python

1. Знайомство з числами в Python
2. Істина чи брехня?
3. Рядки
4. Поєднання всіх тем разом

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").

Завдання
test

Swipe to begin your solution

In this exercise, you'll practice converting float values to integers.

  1. Convert variable1 to an integer and store the result in integer1
  2. Convert variable2 to an integer and store the result in integer2
  3. Convert variable3 to an integer and store the result in integer3

Once converted, you’ll have three interesting numbers! At the end of this chapter, you'll learn why each of these numbers is considered a "perfect number." 🤔

Рішення

Note

A perfect number is an integer that is the sum of its positive proper divisors: 6 = 1+2+3. Our courses don't just help develop in programming.😄

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 1
toggle bottom row

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").

Завдання
test

Swipe to begin your solution

In this exercise, you'll practice converting float values to integers.

  1. Convert variable1 to an integer and store the result in integer1
  2. Convert variable2 to an integer and store the result in integer2
  3. Convert variable3 to an integer and store the result in integer3

Once converted, you’ll have three interesting numbers! At the end of this chapter, you'll learn why each of these numbers is considered a "perfect number." 🤔

Рішення

Note

A perfect number is an integer that is the sum of its positive proper divisors: 6 = 1+2+3. Our courses don't just help develop in programming.😄

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 1
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt