1. What are the key features of Python? If it makes for an introductory language to programming, Python must mean something. These are its qualities: Interpreted Dynamically-typed Object-oriented Concise and simple Free Has a large community 2. Differentiate between lists and tuples. The major difference is that a list is mutable, but a tuple is immutable. Examples: >>> mylist=[1,3,3] >>> mylist[1]=2 >>> mytuple=(1,3,3) >>> mytuple[1]=2 Traceback (most recent call last): File “<pyshell#97>”, line 1, in <module> mytuple[1]=2 TypeError: ‘tuple’ object does not support item assignment 3. Explain the ternary operator in Python. Unlike C++, we don’t have ?: in Python, but we have this: [on true] if [expression] else [on false] If the expression is True, the statement under [on true] is executed. Else, that under [on false] is executed. Below is how you would use it: >>> a,b=2,3 >...
Comments
Post a Comment