Strings and Integers

There are many different types of data in Python, but most of them fall under these two types: Strings and Integers.

Strings

Strings are variables that can be anything, from text to even numbers. Imagine Strings to be a superhero that can transform into anything!

Strings are written in inverted commas, like this-

string = "apple"

When you want to print a string, put it in inverted commas as well-

print("apple")

Integers

Integers are variables with numerical values, in the form of numbers. Integers are like superheroes who only have one form of power!

Unlike Strings, Integers are just a number, so they don’t need the inverted commas-

integer = 3

When you want to print an integer, just type it in-

print(3)

Converting Integers to Strings / Strings to Integers

When you want to change the variables into another form of data, you can use the str() function and the int() function.

The str() function is short for String, and converts Integers to Strings. The int() function is short for Integer, and converts Strings to Integers.

The following code converts an integer to a string-

number = 5
number = str(number)

And the next one converts a string to an integer-

number = "5"
number = int(number)

You can also use the functions when printing to save some space-

number = "5"
print(int(number))

Concatenation

Strings and Integers are very important in Concatenation. You can know more about it here.

Conclusion

That is all for this guide! I hope it was helpful.