- Variable is like a container
# Variable x is containing 12
x = 12
print(x)
# You can either use "" or '' -> write x = "This is a test" or x = 'This is a test'
x = "This is a test"
print(x)
x = 200
# First way
print(x-100)
# Second way - you can put the result in x instead of new variable
x = x - 100
print(x)
# You can either use "" or '' for string
x = 'beautiful '
y = "day"
# First way
print (x+y)
# Second way
z = x+y
print (z)
a, b, c, d = "this is a", "this is b", "this is c", "this is d"
print(a)
print(b)
print(b)
print(d)
k = m = n = 5
print("the value of k is :", k)
print("the value of m is :", m)
print("the value of n is :", n)
x = 2
y = 'hope '
# First way to print hope twice
print(x*y)
# Second way to print hope twice
z = x * y
print(z)
# this is a function # Check the function section to learn how to write and use functions
x = "Flowers"
def combine_words():
print("Yellow " + x)
# When you call function combine_words(), it will consider global variable if there is no local variable
combine_words()
x = "Cars" # This is a global variable
def combine_words():
x = "Flowers" # This is a local variable
print("Yellow " + x)
combine_words() # when you call function combine_words(), it considers local variable
print("Yellow " + x) # when you use print() outside the function, it considers global variable for printing
def combine_words():
global x # although x is defined inside function, it is a global variable because of global keyword
x = "Flowers"
print("Yellow " + x)
combine_words() # when you call function combine_words(), it considers variable defined inside function
print("Yellow " + x) # when you use print() outside the function, it considers global variable for printing
x = "cars"
def combine_words():
global x # although x is defined inside function, it is a global variable because of global keyword
x = "Flowers" # because of global keyword, function ignores x = "Flowers" and sets the value of x = "cars"
print("Yellow " + x)
combine_words() # when you call function combine_words(), in this case it considers global varibale x = "cars"
print("Yellow " + x) # when you use print() outside the function, it considers global variable for printing