Python Assignment
1. Why Python is called Dynamic and Strongly Typed Language?
A. Python is a Dynamically typed language because we don’t have to specify the data type of
variable during it’s creation. Eg, we can simply define a variable in Python as:
a=5
And Python will automatically detect the type of variable a (Int) here.
Now, Python is a Strongly typed language because the operations performed on data will only
work if the data type of both the variables involved is Compatible.
2. What’s Operator Precedence and Associativity?
A. Operator Precedence defines the Priority or order in which different operators are evaluated in
an expression.
Eg, * has higher precedence or priority than + in an expression.
Associativity is when operators of same precedence are present in the same expression.
Priority is given in this case based on if a n operator is left- associative or right-associative.
3. Short Notes on:
a. Programming Cycle in Python:
(i) Understanding a Problem
(ii) Making a step by step plan to solve it
(iii) Writing the Python code for solution
(iv) Testing and Debugging
(v) Deployment of the software
(vi) Version Control
b. Type Conversion: Converting the data type of a value to another data type.
Eg , a =5
print(float(a))
c. Key Features of Python:
(i)Easy to learn and read
(ii) Interpreted Language
(iii) Cross Platform Compatibility
(iv) Object Oriented
(v) Extensive amount of Libraries
(vi) High Level Language
(vii) Open Sourced
(viii) Can be used for many applications such as Web Dev, Data Science and Analysis, AI, Game
Dev ,etc.
d. Data Types supported by Python:
Int, Float, char, str, dict, list, tuple, set, bool, complex, None,etc
e. Expression: (10+2)*3 → 36
4. Expression Evaluation and Float Representation.
A. Expression Evaluation is the computing and obtaining a single value from an expression.
Eg, x = 5
y=3
result = x + y*2
Floating Point Representation is a method used to represent fractional numbers in a computer’s
memory. The data type “float” is used to store floating point numbers.
Eg, f = 2.3
Print(type(f))
5. Python Keywords and Identifier.
A. Python Keyword are reserved words that have their specific meaning in Python and can’t be
used to define a variable, function or class.
Eg, if, else, return, import, is , in, for, while, etc.
Identifiers are names used to represent variables, functions, classes, modules and others.
a-z, A-Z, _ can be used in Identifiers.
Eg, my_var, new_class, etc.
6. Diff between == and is operator.
A. == is used for Value Comparison whereas “is” is used to check whether two objects or variables
refer to the same memory location.
7. Diff between “sep” and “end” parameters of print in Python.
A. The “sep” parameter in print sands for Separator. It specifies the string that will be used to
separate multiple values passed in Print statement.
Eg., print(“Hello”,”World”, sep=”.”)
The “end” parameter in print specifies the string that will be printed at the end of the print
statement.
Eg., print(“Hello”,”World”, end=”_”)
8. a=’5’
b=’17’
print(a+b)
Output: ?
A. Since both are Strings, Output: 517 , due to string concatenation.
9. Explore all the conditional statement in Python using code.
A. a=15
if a<10:
print(“a is less than 10”)
elif a<20:
print(“a is less than 20”)
else:
print(“a is neither less than 10 nor less than 20.”)
10. Python program to output:
*
**
***
****
*****
A. i = 0
for(i<=5):
print(“*” * i)
i=i+1