Python Programming
About Lesson

A variable is a data element that is referring a memory location with an identifier. Since the value at the memory location referring by that data element, can be changed during program execution it is called as variable. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.
Example:
x = 5
y = “John”
print(x)
print(y)

No Declaration
Variables do not need to be declared with any particular type and can even change type after they have been set.
Example:
x = 4 # x is of type int
x = “Sally” # x is now of type str
print(x)

String Variables
String variables can be declared either by using single or double quotes.
Example:
x = “John”
# is the same as
x = ‘John’

Assigning Values to multiple variables
you can assign the same value to multiple variables in one line
Example:
x = y = z = “Orange”
print(x)
print(y)
print(z)

Assign different values to different variables
x, y, z = “Orange”, “Banana”, “Cherry”
print(x)
print(y)
print(z)

The print statement
The print statement is used to print some string or value of a variable or a result of the expression to the console.
Example:
print (“hello, World”)

you can print more than one value using single print statement by separating its arguments with a comma or ‘+’
print(“Python is ” + x)

Eg2:
x = “Python is “
y = “awesome”
z = x + y
print(z)

Eg3:
x = 5
y = 10
print(x + y)

Eg4:
x = 5
y = “John”
print(x + y) #it will gives you error.

You cannot copy content of this page