Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre How to Define a Type | Getting Familiar With Numbers in Python
Data Types in Python

book
How to Define a Type

We've previously come across float and integer types, so now we can tell whether a value is a float or an integer. Can you guess what the result of the math operation 6/1.5 might be? It's easy to calculate that it equals 4, but what type does 4 belong to? It might seem like an integer, but it's actually a float. To confirm its type, you can use the type() function.

variable = 6/1.5
print(variable)
print(type(variable))
123
variable = 6/1.5 print(variable) print(type(variable))
copy
Tâche

Swipe to start coding

An accountant received two reports: one contains the total revenue for the month, and the other records the number of successful transactions. Before calculating the average revenue per transaction, it's important to check if the data types are correct.

  1. Check the type of the number1 variable, which stores the total revenue.
  2. Check the type of the number2 variable, which stores the number of transactions.

Solution

number1 = 88/16e-1
number2 = 12*2

# Print the number and it's type
print("The value of number1 is", number1)
print("The type of number1 is", type(number1))
print("The value of number2 is", number2)
print("The type of number2 is", type(number2))
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 7
number1 = 88/16e-1
number2 = 12*2

# Print the number and it's type
print("The value of number1 is", ___)
print("The type of number1 is", ___(number1))
print("The value of number2 is", ___)
print("The type of number2 is", type(___))

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt