DATA, EXPRESSIONS, STATEMENTS
1. What is meant by interpreter?
An interpreter is a computer program that executes instructions written in a programming language. It can either execute the source code directly or translate the source code in a first step into a more efficient representation and executes this code.
2. How will you invoke the python interpreter?
The Python interpreter can be invoked by typing the command "python" without any parameter followed by the "return" key at the shell prompt.
3. What is meant by interactive mode of the interpreter?
Interactive mode is a command line shell which gives immediate feedback for each statement, while running previously fed statements in active memory. As new lines are fed into the interpreter, the fed program is evaluated both in part and in whole.
4. Write a snippet to display “Hello World” in python interpreter.
In script mode:
>>> print "Hello World"
In Interactive Mode:
5. What is a value? What are the different types of values?
A value is one of the fundamental things – like a letter or a number – that a program manipulates. Its types are: integer, float, boolean, strings and lists.
6. Define a variable and write down the rules for naming a variable.
A name that refers to a value is a variable. Variable names can be arbitrarily long. They can contain both letters and numbers, but they have to begin with a letter. It is legal to use uppercase letters, but it is good to begin variable names with a lowercase letter.
7. Define keyword and enumerate some of the keywords in Python.
A keyword is a reserved word that is used by the compiler to parse a program. Keywords cannot be used as variable names. Some of the keywords used in python are: and, del, from, not, while, is, continue.
8. Define statement and what are its types?
A statement is an instruction that the Python interpreter can execute. There are two types of statements: print and assignment statement.
9. What do you meant by an assignment statement?
An assignment statement creates new variables and gives them values:
Eg 1: Message = 'And now for something completely different'
Eg 2: n = 17
10. What is tuple?
A tuple is a sequence of immutable Python objects. Tuples are sequences, like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. Creating a tuple is as simple as putting different comma-separated values. Comma-separated values between parentheses can also be used.
Example: tup1 = ('physics', 'chemistry', 1997, 2000);
11.What is an expression?
An expression is a combination of values, variables, and operators. An expression is evaluated using assignment operator.
Examples: Y=x + 17
12. What do you mean by an operand and an operator? Illustrate your answer with relevant example.
An operator is a symbol that specifies an operation to be performed on the operands. The data items that an operator acts upon are called operands. The operators +, -, *, / and ** perform addition, subtraction, multiplication, division and exponentiation. Example: 20+32
In this example, 20 and 32 are operands and + is an operator.
13. What is the order in which operations are evaluated? Give the order of precedence.
The set of rules that govern the order in which expressions involving multiple operators and operands are evaluated is known as rule of precedence. Parentheses have the highest precedence followed by exponentiation. Multiplication and division have the next highest precedence followed by addition and subtraction.
14. Illustrate the use of * and + operators in string with example.
The * operator performs repetition on strings and the + operator performs concatenation on strings.
15. What is the symbol for comment? Give an example.
# is the symbol for comments in Python.
# compute the percentage of the hour that has elapsed
16. What is function call?
A function is a named sequence of statements that performs a computation. When we define a function, we specify the name and the sequence of statements. Later, we can “call” the function by its name called as function call.
17. Identify the parts of a function in the given example.
>>> betty = type("32")
>>> print betty
The name of the function is type, and it displays the type of a value or variable. The value or variable, which is called the argument of the function, is enclosed in parentheses. The argument is 32. The function returns the result called return value. The return value is stored in betty.
18. What is a local variable?
A variable defined inside a function. A local variable can only be used inside its function.
19. What is the output of the following?
a. 32.0 The float function converts integers to floating-point numbers.
b. 3.14159 The float function converts strings to floating-point numbers.
20. What do you mean by flow of execution?
In order to ensure that a function is defined before its first use, we have to know the order in which statements are executed, which is called the flow of execution. Execution always begins at the first statement of the program. Statements are executed one at a time, in order from top to bottom.
21. Write down the output for the following program.
first = 'throat'
second = 'warbler'
print first + second
22. Give the syntax of function definition.
def NAME( LIST OF PARAMETERS ):
23. Explain the concept of floor division.
The operation that divides two numbers and chops off the fraction part is known as floor division.
24. What is type coercion? Give example.
Automatic method to convert between data types is called type coercion. For mathematical operators, if any one operand is a float, the other is automatically converted to float.
>>> minute = 59
>>> minute / 60.0
25. Write a math function to perform √2 / 2.
>>> math.sqrt(2) / 2.0
26. What is meant by traceback?
A list of the functions that tells us what program file the error occurred in, and what line, and what functions were executing at the time. It also shows the line of code that caused the error.
1. What is interpreter?
2. What are the two modes of python?
3. List the features of python.
4. List the applications of python
5. List the difference between interactive and script mode
6. What is value in python?
7. What is identifier? and list the rules to name identifier.
8. What is keyword?
9. How to get data types in compile time and runtime?
10. What is indexing and types of indexing?
11. List out the operations on strings.
12. Explain slicing?
13. Explain below operations with the example (i)Concatenation (ii)Repetition
14. Give the difference between list and tuple
15. Differentiate Membership and Identity operators.
16. Compose the importance of indentation in python.
17. Evaluate the expression and find the result
18. Write a python program to print ‘n’ numbers.
19. Define function and its uses
20. Give the various data types in Python
21. Assess a program to assign and access variables.
22. Select and assign how an input operation was done in python.
23. Discover the difference between logical and bitwise operator.
24. Give the reserved words in Python.
25. Give the operator precedence in python.
26. Define the scope and lifetime of a variable in python.
27. Point out the uses of default arguments in python
28. Generalize the uses of python module.
29. Demonstrate how a function calls another function. Justify your answer.
30. List the syntax for function call with and without arguments.
31. Define recursive function.
32. What are the two parts of function definition? give the syntax.
33. Point out the difference between recursive and iterative technique.
34. Give the syntax for variable length arguments.