Home » Python programs

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?
Submitted by IncludeHelp, on July 29, 2018

Define an integer value in a variable and print it in Python.

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

Program:

# 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, read more about, String.format() Method.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.