Unit-I Question Bank
Unit-I Question Bank
PART A
1
What is the difference between intermediate mode and script mode?
• In intermediate mode, you type Python expressions into the Python
Interpreter window, and the interpreter immediately shows the result.
For Example:
>>> print('Keep calm and bubble on')
>>> Keep calm and bubble on
>>>
• 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,
3 K2
printed, and so on.
For example:
print(' This is a script mode window')
print(' Exit from script mode")
Using File | Save and save the script under the name 'Test.py'.
Execute the script from the Run menu or using F5. The above two
messages will get printed.
This is a script mode window
Exit from script mode
>>>
List out the features of python.
• Easy to Use
• Expressive Language
• Interpreted Language
4 K1
• Cross-platform language
• Free and Open Source
• Object-Oriented language
• Extensible
2
What are the different data types available in Python?
The different data types available in Python are
• Numbers (int, float, complex)
• None
• Bool or Boolean
5 K1
• List
• Tuples
• Dictionary
• String
• Set
What is meant by python numbers?
Number data types store numeric values. Number objects arecreated
when you assign a value to them.
Python supports four different numerical types:
Example:
str = 'Hello World!'
print str[0] # Prints first character of the string
Output: H
3
Mention the features of lists in python
• Lists are the most versatile of Python's compound data types.
• Alist contains items separated by commas and enclosed within square
brackets [].
• A list in Python is used to store the sequence of various types of data.
8 • A list can be defined as a collection of values or items of different types. K1
For example,
list1 = [1, 2, "Python", "Program", 15.9]
print(list1)
Output:
[1, 2, ‘Python’, ‘Program’, 15.9]
9 What is tuple? What is the difference between list and tuple?
It is an absolute collection of Python objects separated by commas i.e a
tuple can’t be changed or modified after its creation.
S.No List Tuple
1 Lists are mutable Tuples are immutable
2 The list is better for Tuple data type is appropriate
performing operations, for accessing the elements. K4
such as insertion and
deletion
3 Lists consume more Tuple consumes less memory
memory as compared to the list
10 What is a variable?
• A variable is a name that refers to a value stored in memorylocation
• Python variables are case sensitive.
K1
• Python variables can start with a letter a-z, A-Z or _(underscore),followed
by letters, numbers or underscore.
Ex: a=10, a is a variable
11 What are keywords?
• Keywords are the reserved words in Python.
K1
• We cannot use a keyword as variable name, function name or any
other identifier.
4
• They are used to define the syntax and structure of the Python
language
• In Python. keywords are case sensitive. There are 33 keywords in
Python.
Example: False, class, finally, return
12 What are the rules for writing an identifier?
• Identifiers can be a combination of letters in lowercase (a to z) or uppercase
(A to Z) or digits (0 to 9) or an underscore (_). Names like myClass, var_1
and print_this_to_screen, all are valid example.
• An identifier cannot start with a digit. 1variable is invalid, but variable1 is
K1
perfectly fine.
• Keywords cannot be used as identifiers.
• We cannot use special symbols like!, @, #, $, % etc. in our identifier.
• Identifier can be of any length.
5
15 What is indent in Python? Why we require indentation in python?
Python functions have no explicit begin or end, and no curly braces to mark
where the function code starts and stops. The only delimiter is a colon (:) and the
indentation of the code itself. K1
Leading whitespace (spaces and tabs) at the beginning of a logical line is
used to compute the indentation level of the line, which in turn is used to
determine the grouping of statements.
16 What are the rules in declaring Python variables?
• A Python variable name must start with a letter or the underscore
character.
• A Python variable name cannot start with a number.
• A Python variable name can only contain alpha-numeric characters
K1
and underscores (A-z, 0-9, and _).
• Variable in Python names are case-sensitive (name, Name, and
NAME are three different variables).
• The reserved words (keywords) in Python cannot be used to name the
variable in Python.
17 What is Boolean value? K1
The Boolean is a datatype that accepts two inputs.
o True K1
o False
The value of True is 1 and False is 0
18 What is a set in Python?
A set is an unordered collection of items. Every element is unique (no
duplicates) and must be immutable (which cannot be changed). However, the set
itself is mutable. We can add or remove items from it. Sets can be used to
perform mathematical set operations like union, intersection, symmetric
difference etc.
K1
Example:
#Create a Set
thisset = {"apple", "banana", "cherry"}
print(thisset)
Output:
{‘cherry’, ‘banana’, ‘apple’}
6
19 Can you change a set in Python?
Sets are mutable. However, since they are unordered, indexing has no
K1
meaning. We cannot access or change an element of a set using indexing or
slicing. Set data type does not support it.
20 Define a keyword None.
The None keyword is used to define a null value, or no value at all.
None is not the same as 0, False, or an empty string. None is a data type of its own
(None Type) and only None can be None.
Example:
x = None
if x:
print("Do you think None is True?") K1
elif x is False:
print ("Do you think None is False?")
else:
print("None is not True, or False, None is just None...")
Output:
None is not True, or False, None is just None…
22 What is an expression?
An expression is a combination of operators and operands that is
interpreted to produce some other value. It has 8 types.
1. Constant Expressions
2. Arithmetic Expressions
3. Integral Expressions K1
4. Floating Expressions
5. Relational Expressions
6. Logical Expressions
7. Bitwise Expressions
8. Combinational Expressions
7
23 Define Input and Print functions.
In Python, program output is displayed using the print() function, while user
input is obtained with the input() function. Python treats all input as strings by
default, requiring explicit conversion for other data types.
K2
Example:
# Here, we take input from the user and then display it.
name = input("Enter your first name: ")
print("Hello! " + name)
24 Define Command line arguments.
The arguments that are given after the name of the program in the command
line shell of the operating system are known as Command Line Arguments.
Python provides various ways of dealing with these types of arguments. The
three most common are: K1
• Using sys.argv
• Using getopt module
• Using argparse module
8
Q.No PART – B BTL*