Saturday, 4 December 2021

Write a program to illustrate Variable assignment in PYTHON

 In any programming language variables are named memory location used to hold the value. Every variable have its type. But in Python it is not necessary to specify the type of variable because Python automatically infer its type when we assign value to it.

we can say more strongly, a Python variable is created when we assign value to it. For complete tutorial on Python click here

The following example shows variable assignment in Python

x=5
y=10.25
z="hello" #Variables do not need to be declared with any particular type
print(x)
print(y)
print(z)
print("--------------------------------------------------------")
#If you want to know the data type of a variable, this can be done with type

x=5
y=10.25
z="hello" 
print(type(x))
print(type(y))
print(type(z))
print("--------------------------------------------------------")
#Python allows you to assign values to multiple variables in one line:

a, b, c = "C", "Java", "Python"
print(a)
print(b)
print(c)
print("--------------------------------------------------------")
#you can assign the same value to multiple variables in one line:

a=b=c = "Computer"
print(a)
print(b)
print(c)

The following is the output of above program

5
10.25
hello
--------------------------------------------------------
<class 'int'>
<class 'float'>
<class 'str'>
--------------------------------------------------------
C
Java
Python
--------------------------------------------------------
Computer
Computer
Computer


0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top