Python program to define an integer value and print it

Here, we will learn how to define an integer value to a variable in Python and how to print it? By IncludeHelp Last updated : April 08, 2023

The task is to define an integer value in a variable and print it in Python.

Define an integer value to a variable

Its very simple to declare a variable and define an integer value to it, there is no need to define any type of keyword to make the variable an integer, we have to just assign an integer value and variable is able to store and then we can print it.

Syntax

variable_name = value

Example

If we want to assign 10 to a variable named num, the statement will be:

num = 10

Python program to define an integer value and print it

# Python program to define an 
# integer value and print it 

# declare and assign an integer value 
num = 10

# print num 
print "num =",num 
# print using format
print "num = {0}".format(num)

# assign another value
num = 100

# print num 
print "num =",num 
# print using format
print "num = {0}".format(num)

Output

    num = 10
    num = 10
    num = 100
    num = 100

Note: In this program, we also used format() method to print the value as string formatted.

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.