Python - Variables
A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Every value in Python has a datatype.
Python is object oriented programming language. Every variable in Python is an object. There are Different types of variables.
To Create a Variable in Python,all you need to specify the variable name then assign a value to it
<variable name> = <value>
Python uses = to assign value to variables.There's no need to declare in advance,assigning a value to a variable itself declares and initializes the variable with that value.There is no way to declare a variable without assigning it an intial value.
a = 2
b = "sri"
print(a)
print(b)
#output = 2
#output = sri
Python allows you to assign values to multiple variables in one line
< variable names> = < value1,value2,value3.....>
a, b, c = 1, 2, 3
print(a, b, c)
#output: 1 2 3
The Python 'print' statement is often used to output variables.
To combine both text and a variable, Python uses the + character
a = "language"
print("Python is a " + a)
#output: Python is a language
a = 4
b = 3
print(a + b)
#output: 7
Variables that are created outside of a function (as in all of the examples above) are known as global variables.
Global variables can be used by everyone, both inside of functions and outside.
a = "language"
def myfunc():
print("Python is a " + x)
myfunc()
#output: Python is a language