How to Create Integer in Python With Easy Examples

In this tutorial, learn how to create integer in python. The short answer is: assign a numeric value without a decimal. You can assign a positive or negative value to a variable to create an integer.

Create Integer in Python With Positive Value

To create a positive integer variable, you have to assign a positive value to it. After you assign a positive numeric value without any decimal point. You can start using it on your Python programming as a positive integer variable. You may also like to read how to create a variable in Python.

To print the integer variable in the output, you have to use the print statement of Python. Check the below example and also find out if it is a python integer variable. Use the Python type() to check the type of the Python variable.

Output

10
<class ‘int’>

The above example prints the positive integer variable. After that, the type() function finds the type of the variable and print the type in the output. Check the output to find out how it prints the variable type.

Bonus: download a Free Python cheat sheet that will show you 20+ most important examples to learn in Python.

Declare Numeric Int Variable in Python With Negative Value

In addition to the above positive integer variable type. Python also allows creating a variable with a negative value. To declare a negative integer variable of Python. You have to assign a non-decimal numeric value with a minus(-) sign before the value.

See the example below to find out how to declare a numeric type variable in python with a negative value. Also check, if the negative numeric value variable is of integer type using the type function.

Output

-23
<class ‘int’>

The above prints the negative integer value and the type of the integer variable. You can declare your own integer variable and apply different operations on it.

DOWNLOAD Free PYTHON CHEAT SHEET

Reference

I hope you like this tutorial on how to create integers in Python.