views

Open your Python project in your text editor. You can use any basic text editor on your computer, or a Python-integrated coding editor. If you're just starting out with Python, make sure to check out this article for more information about basic Python functions and mechanics.

Find your integer variable's name. Find the first instance you created your integer variable in your code, and note down the variable's name. For example, if you define an integer as i = 5, your integer's variable name is i and it's value is 5.

Type s = str(var) on a new line. Start a new line in your code, and enter the str() function. This function allows an explicit type conversion. You can use it to convert an integer to a string object . This will create new string object named s. This will be the string conversion of your integer. On some versions, you can also use the var.__str__() function instead of str(var).

Replace var in the function with the name of your integer variable. This will allow you to pull the integer value from the specified variable, and convert it to a string object. For example, if you're converting the integer variable i = 5, your new line should look like s = str(i).

Press ↵ Enter or ⏎ Return on your keyboard. This will import your integer's value, and convert it to string in the new string object.

Type print "The number is " + s in a new line. This will pull your new string object, and print it with the text here below. If your new string object is named differently, replace s here with the name of your own string object. For example, if you did myNewString = str(i), then your line here should look like print "The number is " + myNewString.

Press ↵ Enter or ⏎ Return on your keyboard. This will process the line command, and print your new string along with the text below. For example, if your initial integer value was 10, this will print The number is 10.
Comments
0 comment