Integers and strings | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Integers and strings

Why is the int sign ever needed? What is an example of when I would need that in a string? Could I not just make the numbers I wanted outside of the string.

14th Jun 2019, 5:17 AM
Maggie Jones
Maggie Jones - avatar
4 Answers
+ 2
age = int(input("Enter your age: "))
14th Jun 2019, 5:27 AM
Trigger
Trigger - avatar
+ 2
num1 = int(input()) num2 = int(input()) print(num1 + num2)
14th Jun 2019, 5:27 AM
Trigger
Trigger - avatar
+ 2
for i in range(int(input("How many times will the loop be run? "))):
14th Jun 2019, 5:28 AM
Trigger
Trigger - avatar
+ 1
If you want to multiplicate something, that can't be multiplicated with floats, such as lists, [6, 3, 1]*int(5.5) => [6, 3, 1]*5. You can also test whether a float is a whole number by testing int(x) == x
14th Jun 2019, 9:46 AM
Seb TheS
Seb TheS - avatar