+ 3

Difference between operators int, float and str

23rd Jun 2017, 2:08 PM
Krepser
Krepser - avatar
5 odpowiedzi
+ 6
int = whole number float = number with decimal str = "string in quotes" examples 1 = int 1.5 = float "1" = str
23rd Jun 2017, 8:16 PM
Nobody
+ 5
Int = numbers - "1" Float = numbers with a floating decimal - "1.234567" str = a string of characters - "This is a string! 123! Weee!"
23rd Jun 2017, 2:13 PM
AgentSmith
+ 3
int > whole numbers string > anything inside --> " "
23rd Jun 2017, 2:18 PM
Gil Jr.
0
Ebat ti top
5th Jul 2017, 3:08 PM
FLeKsO
FLeKsO - avatar
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.
1st Mar 2018, 2:30 AM
Dan C
Dan C - avatar