Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (7)

Q1..What is the difference between intermediate mode and script mode?

In immediate mode, you type Python expressions into the Python Interpreter window, and the interpreter immediately shows the result. Alternatively, you can write a program in a file and use the interpreter to execute the contents of the file. Such a file is called a script. Scripts have the advantage that they can be saved to disk, printed, and so on

Q2. List some few common Exception types and explain when they occur.

ArithmeticError- Base class for all errors that occur for numeric calculations. OverflowError- Raised when a calculation exceeds maximum limit for a numeric type. ZeroDivisionError- Raised when division or modulo by zero takes o place. ImportError- Raised when an import statement fails. IndexError- Raised when an index is not found in a sequence. RuntimeError- Raised when a generated error does not fall into any category



Q3.Mention five benefits of using Python?

Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc. Python does not require explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically Provide easy readability due to use of square brackets Easy-to-learn for beginners Having the built-in data types saves programming time and effort from declaring variables

Q4.What are python strings?

Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end. The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator. str = 'Hello World!' print str[0] # Prints first character of the string o/p: H

Q5 .Mention the features of lists in python


Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type. The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1. The plus (+) sign is the list concatenation operator, and the asterisk (*) is the repetition operator. For example – list = [ 'abcd', 786 , 2.23,'john', 70.2 ] print list[0] o/p a b c d



Post a Comment

0 Comments