+ 3

# Difference between operators int, float and str

5 Respostas

+ 6

int = whole number
float = number with decimal
str = "string in quotes"
examples
1 = int
1.5 = float
"1" = str

+ 5

Int = numbers - "1"
Float = numbers with a floating decimal - "1.234567"
str = a string of characters - "This is a string! 123! Weee!"

+ 3

int > whole numbers
string > anything inside --> " "

0

Ebat ti top

0

int is the data type for storing numerical values that are "integers". "Integers" are not just "whole numbers" though.
"Natural numbers" are every positive, non-zero, non-decimal number. (ie. 1, 2, 3, 4...)
"Whole numbers" comprise all the "natural numbers" + zero. (ie. 0, 1, 2, 3, 4...)
"Integers" comprise all the "whole numbers", both positive and negative. (ie. ...-3, -2, -1, 0, 1, 2, 3...)
"Float" numbers are floating point numbers which comprise all rational and irrational numbers in the "real" number set. They have a certain amount of precision or number of decimal points that they can store.
"str" is a string which is just a list of characters. That is, they are not numerical values. A variable that holds, let's say 7, as a string does not return 7. it returns "7". Strings cannot be used in mathematical operations unless you do something special like using the "eval" function in Python or converting the string to a numerical value before the calculation.