Python.
● Q No. 10, 12, 13, 14, 15, 16, 17, 18, 21, 22, 23
10. What are variables? Give examples.
- Variables are containers to store data.
➔ Example: Program:
➔ X = 5
Y = “hai”
print (x)
print (y)
12. Write a program to swap 2 numbers using variables.
➔ x=5
y=6
z=x
x=y
y=z
print(x)
print(y)
14)Explain variables/variable names and data.
➔ Variable names or variables store values/data.
➔ Example:
➔ q=5
➔ Here, q is a variable or variable name. 5 is data. In short, the
value(s) to the left of = is variable/variable name and the
value(s) to the right of = is data.
15)Define the rules for declaring Python variable names.
➔ A variable name must start with a letter or the underscore
character
➔ A variable name cannot start with a number
➔ A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
➔ Variable names are case-sensitive (age, Age and AGE are three
different variables)
16)Give examples of valid variable names.
➔ a = 5
➔ my_var = 5
➔ _a = 5
➔ aREa = 5
➔ A = 5
➔ a2 = 5
➔ Hein_Thu_Aung = 5
17) Give examples of invalid variable names.
➔ 2a = 5
➔ my-var = 5
➔ my var = 5
18) Can 1 data be assigned to multiple variable names?
Yes.
➔ Example:
➔ x= “green”
➔ y= “green”
➔ z= “green”
➔ print(x)
➔ print(y)
➔ print(z)
21)What is string concatenation?
➔ Concatenation is the process of appending(adding) one string to
the end of another string.
22) Write a program for String concatenation.
➔ x = "Python "
➔ y = "is "
➔ z = "awesome"
➔ a = x + y + z
➔ print(a)
➔ (or)
➔ x = "Python "
➔ y = "is "
➔ z = "awesome"
➔ print(x , y , z)
➔ Output:
Python is awesome
23) Write a program using variables and 4 arithmetic operators.
➔ x = 15
➔ y = 5
➔ a=x+y
➔ b=x-y
➔ c=x*y
➔ d=x/y
➔ print("the sum is", a)
➔ print("the difference is", b)
➔ print("the product is", c)
➔ print("the value of division is", d)
➔ Output:
the sum is 20
the difference is 10
the product is 75
the value of division is 3.0