0% found this document useful (0 votes)
20 views9 pages

Unit-I Question Bank

The document discusses various concepts related to Python programming such as history and features of Python, different modes, data types, variables, operators, functions, comments and indentation. It provides examples and explanations of these concepts in the form of questions and answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Unit-I Question Bank

The document discusses various concepts related to Python programming such as history and features of Python, different modes, data types, variables, operators, functions, comments and indentation. It provides examples and explanations of these concepts in the form of questions and answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

JERUSALEM COLLEGE OF ENGINEERING, CHENNAI 100

(Common to all branches)


ACADEMIC YEAR EVEN (2023-2024)
I YEAR II SEM

Sub Code: JCS2201


Sub Title: PYTHON PROGRAMMING
Unit: 1
Title of the Unit: INTRODUCTION TO PYTHON PROGRAMMING
History of Python, Features, Installing Python, Demo of Interactive and Script Mode
Programming, Identifiers, Reserved Words, Indentation, Comments, Variables, Data Types and
its Conversion, Operators and its Precedence, Expressions, Input and Print functions, Command-
Line arguments.
Course objective: To provide an introduction to Python Programming Language.
Course Outcome: To understand the evolution of Python and run basic python programs.

PART A

Q.No. Question BTL*


What is Python?
• Python is a general purpose, interpreted, open source, object- oriented,
high level language.
1
• Python is considered a scripting language and is often used for creating K1
Web applications and dynamic Web content.
• Python was developed by Guido van Rossum.
What are the basic modes available in Python?
• Python has two basic modes:
o Normal/Interpreted/Script Mode
o Interactive Mode
2
• The Interpreted mode is the mode where the scripted and finished .py K1
files are run in the Python interpreter.
• Interactive mode is a command line shell which gives immediatefeedback
for each statement.

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:

6 • int (signed integers) K1


• long (long integers, they can also be represented in octal and
hexadecimal)
• float (floating point real values)
• complex (complex numbers)
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 singleor 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.
7 K1
• The plus (+) sign is the string concatenation operator and the asterisk
(*) is the repetition operator.

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.

13 How can we determine the data type of a given variable?


• Everything in Python is an object, and every object has an identity, a type
and a value.
• To determine a variable type, we can use type ( )
K1
Ex:
>>>a=456
>>>type(a)
<class ‘int’>
14 What are comments in python?
• Comment tells the user/reader what a section of code does.
• The comments in python begin with # symbol.
• Comments are not read by interpreter and are non-executablestatements K1
#Addition of 2 numbers
#c=a+b

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…

21 Define operator precedence.


Operators have different levels of precedence, which determine the order in
which they are evaluated. When multiple operators are present in an expression, K1
the ones with higher precedence are evaluated first.

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*

1 Write a short note on history of Python. K3


2 Illustrate interpreter and interactive mode in python with example. K3
3 Write in detail about keywords in python with example. K3
4 Write in detail about data types in python with suitable example. K3
5 Explain in detail about the features of Python. K3
Discuss the following data type conversions functions in detail with
example.
a) int()
6 K4
b) float()
c) complex()
d) bool()
Write the following python programs.
a. Exchange the value of two variable
b. To find the sum of digits in a number
c. To find the area and perimeter of a circle
7 d. To find the square and cube of a number K4
e. To find the roots of a quadratic equation
f. To find the square root and cube root of a number
g. To calculate Simple Interest
h. To convert Celsius to Fahrenheit
Write a python code which takes the following numbers as input -
8 8.5, -0.9, 0.6, 1.3 and 2.5. Apply the trunc(), floor() and ceil() and K4
discuss the difference between these functions clearly.

9 Explain Operators and its precedence with an example program. K3

Explain Command line arguments.


10 K3

*BTL – Blooms Taxonomy Level

You might also like