Today, we are here to clear up the issue of crucial short questions in Python Programming Btech AKTU, and we hope that this question will be useful for your forthcoming Python programming test.
Dudes 🤔.. You want more useful details regarding this subject. Please keep in mind this as well. Important Questions For Python Programming: *Unit-01 *Unit-02 *Unit-03 *Unit-04 *Unit-05 *Short-Q/Ans *Question-Paper with solution 21-22
UNIT-1: INTRODUCTION AND BASICS | Short important
Q1. What is Python?
Ans. Python is a high-level, interpreted, interactive and object-oriented scripting language. It is a highly readable language. Unlike other programming languages, Python provides an interactive mode similar to that of a calculator.
Q2. What are the difference between Java and Python?
Ans.
Feature | Java | Python |
Syntax | The syntax of Java is complex than Python. | The syntax of Python is easier than Java |
Speed | Java is statically typed programming, makes it faster | Python is manually typed, makes it slower. |
Code | Longer lines of code than python | Shorter lines of code than Java. |
Q3. What are the features of Python?
Ans. Features of Python :
- 1. The code written in Python is automatically compiled to byte code and executed.
- 2. Python can be used as a scripting language, as a language for implementing web applications, etc.
- 3. Python supports many features such as nested code blocks, functions, classes, modules and packages.
- 4. Python makes use of an object oriented programming approach.
- 5. It has many built-in data types such as strings, lists, tuples, dictionaries, etc.
Q4. What are the different ways of starting Python?
Ans. There are three different ways of starting Python :
- 1. Running a script written in Python.
- 2. Using a graphical user interface (GUI) from an Integrated Development Environment (IDE),
- 3. Employing an interactive approach.
Q5. Which character is used for commenting in Python?
Ans. Hash mark (#) is used for commenting in Python.
Q6. How is Python an interpreted language?
Ans. Python is called an interpreted language because it goes through an interpreter, which turns the Python code into the language understood by processor of the computer.
Q7. What type of language is python?
Ans. Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
Q8. Define the type () function.
Ans. Type () function in Python programming language is a built-in function which returns the datatype of any arbitrary object. The object is passed as an argument to the type() function. Type() function can take anything as an argument and return its datatype, such as integers, strings, dictionaries, lists, classes, module, tuple, functions, etc.
Q9. Define the unary operator.
Ans. Unary operators are operators with only one operand. These operators are basically used to provide sign to the operand.
+, -, are some unary operators.
Q10. What do you mean by binary operator ?
Ans: Binary operators are operators with two operands that are manipulated to get the result. They are also used to compare numeric values and string values.
**, %, <<, >>, &, |, ^, <, >, <=, >=, ==, !=, <> are some binary operators.
Q11. What is the purpose of the PYTHONPATH environment variable?
Ans. Pythonpath has a role similar to PATH. This variable tells Python Interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by Python Installer.
Q12. What is the difference between list and tuples in Python?
Ans.
List | Tuples |
Lists are mutable, i.e., they can be edited. | Tuples are immutable (they are lists that cannot be edited). |
Lists are usually slower than tuples. | Tuples are faster than lists. |
Syntax :list_ 1 [10, bachelorExam, 20] | Syntax :tup 1 (10, bachelorExam, 20) |
Q13. What is the difference between Python arrays and lists.
Ans
Arrays | Lists |
Arrays can only store homogeneous data (data of the same type). | Lists can store heterogeneous and arbitrary data. |
Arrays use less memory to store data. | Lists require more memory to store data. |
The length of an array is pre-fixed while creating it, so more elements cannot be added. | The length of a list is not fixed, so more elements can be added. |
Q14. Can we make multiline comments in Python?
Ans. Python does not have a specific syntax for including multiline comments like other programming languages. However, programmers can use triple-quoted strings (docstrings) for making multiline comments as when a docstring is not used as the first statement inside a method, it is ignored by Python parser.
Q15. Do we need to declare variables with data types in Python?
Ans. No. Python is a dynamically typed language, i.e., Python Interpreter automatically identifies the data type of a variable based on the type of value assigned to the variable.
Q16. In some languages, every statement ends with a semicolon (;). What happens if you put a semicolon at the end of a Python statement ?
Ans. Python allows semicolon to use as a line terminator. So no error will occur if we put a semicolon; at the end of python statement.
Q17. Mention five benefits of using Python.
Ans. Benefits of Python :
- 1. Python is easy to learn.
- 2. Most automation, data mining, and big data platforms depend on Python. This is because it is the ideal language to work with for general purpose tasks.
- 3. Python provides productive coding environment.
- 4. It supports extensive libraries.
- 5. Python uses different frameworks to simplify the development process.
Q18. Define floor division with example.
Ans. Floor division returns the quotient in which the digits after the
decimal point are removed. But if one of the operands (dividend and divisor) is negative, then the result is floored, i.e., rounded away from zero (means, towards the negative of infinity). It is denoted by “//”.
For example:
5.0 // 2
2.0
Q19. List some Python IDEs.
Ans. Some Python IDEs are:
- 1. PyCharm
- 2. Spyder
- 3. PyDev
Q20. Mention some of the reserved keyword in Python.
Ans.
- 1. and
- 2. false
- 3. is
- 4. pass 5. return
- 6. def
Q21. Give an example of assigning one variable value to another.
Ans.
>>> name1 = ‘Albert’
>>> name2 = name1
>>> name2
‘Albert’ # Output
>>>
Q22. Give an example of different types of values to the same variable.
Ans.
>>> amount = 50
>>> amount
50 # Output
>>> amount = ‘Fifty’
>>> amount
‘Fifty’ # Output
>>>
Q23. What are the types of type conversion?
Ans. Two types of type conversion are:
- 1. Implicit type conversion
- 2. Explicit type conversion
Q24. What are types of assignment statements?
Ans. Three type of assignment statements are:
- 1. Value-based expression on RHS
- 2. Current variable on RHS
- 3. Operation on RHS
Q25. List the categories of operators.
Ans. Following are the seven categories of operators :
- 1. Arithmetic operators.
- 2. Assignment operators.
- 3. Bitwise operators.
- 4. Comparison operators.
- 5. Identity operators.
- 6. Logical operators.
- 7. Membership operators.
Q26. Name the tools that are used for static analysis.
Ans.
- 1. Pychecker
- 2. Pylint
Q27. What are the different data types used in Python?
Ans. Python has six basic data types which are as follows:
- 1. Numeric
- 2. String
- 3. List
- 4. Tuple
- 5. Dictionary
- 6. Boolean
Q28. Define operator associativity with its type.
Ans.
- 1. Associativity decides the order in which the operators with the same precedence are executed.
- 2. There are two types of associativity :
- a. Left to right: In left-to-right associativity, the operator of the same precedence are executed from the left side first.
- b. Right to left: In right-to-left associativity, the operator of the same precedence are executed from the right side first.
UNIT-2: CONDITIONALS AND LOOPS | Important Short Question
1. What are the factors for expression evaluation?
Ans.
- 1. Precedence: It is applied to two different class of operators. That is,+ and*, and *, AND & OR, etc.
- 2. Associativity: It is applied to operators of same class. That is, * and *,+ and -, * and /, etc.
- 3. Order: Precedence and associativity identify the operands for each operator. While evaluating an assignment, the RHS is evaluated before LHS.
Q2. What is the range () function?
Ans. The range () function is a built-in function in Python that helps us to iterate over a sequence of numbers. It produces an iterator that follows an arithmetic progression.
Q3. Give an example of range () function.
Ans.
>>> range (8)
[0, 1, 2, 3, 4, 5, 6, 7]
range (8) provides a sequence of number 0-7. That is to say range (n) generates a sequence of number that starts with 0 and end with (n – 1).
Q.4. Explain begin and end arguments passed by range () function.
Ans.
>>> range (3, 9)
[3, 4, 5, 6, 7, 8]
We provided the begin index with 3 and the end index with 9. Hence, the range function generates a sequence iterator of number that starts from 3 and ends at 8.
Q5. Define the term alternative execution.
Ans. The alternative execution provides two possibilities and the condition determines which one is to be executed. This is the second form of the if statement.
Q6. What do you mean by block?
Ans. The intended statements that follow the conditional statements are called block. The first unintended statement marks the end of the block.
Q7. What will be the output of the following code:
Str [0:4] if str=”Hello”
Ans. ‘Hello’
Q8. What are control statements?
Ans. A control statement is a statement that determines the control flow of a set of instructions. There are three fundamental forms of control that programming languages provide: sequential control, selection control, and iterative control.
Q9. What is short-circuit evaluation ?
Ans. In short-circuit (lazy) evaluation, the second operand of Boolean operators AND and OR is not evaluated if the value of the Boolean expression can be determined from the first operand alone.
Q10. Define the terms: header, suite and clause.
Ans. A header in Python starts with a keyword and ends with a colon. The group of statements following a header is called a suite. A header and its associated suite are together referred to as a clause.
Q11. What do you mean by iterative control ?
Ans. An iterative control statement is a control statement providing the repeated execution of a set of instructions. An iterative control structure is a set of instructions and the iterative control statement(s) controlling their execution.
Q12. What do you mean by definite loop?
Ans. A definite loop is a program loop in which the number of times the loop will iterate can be determined before the loop is executed.
Q13. What do you mean by indefinite loop?
Ans. An indefinite loop is a program loop in which the number of times that the loop will iterate cannot be determined before the loop is executed.
Q14. Is indentation optional in Python?
Ans. No indentation in Python is compulsory and is part of its syntax. Indentation is a way of defining the scope and extent of the block of codes. Indentation provides better readability to the code.
Q15. What happen if break statement is used in for loop?
Ans. If the break statement in a for loop is executed then the else part of that for loop is skipped.
Q16. What is raw_input() function?
Ans. Raw_input() takes the input from the user but it does not interpret the input and also it returns the input of the user without doing any changes.
Q17. Differentiate fruitful functions and void functions.
Ans. The main difference between void and fruitful functions in python is:
- 1. Void does not return any value
- 2. Fruitful function returns some value
UNIT-3: FUNCTION AND STRINGS
Q1. Define traversing of string. Give an example.
Ans. Traversal is a process in which we access all the elements of the string one by one using some conditional statements such as for
loop, while loop, etc.
Q2. What are escape characters ?
Ans. The backslash character (/) is used to escape characters. It converts difficult-to-type characters into a string. For example, we need the escaping character concept when we want to print a string with double quotes or single quotes. When single or double quotes are used with the string, Python normally neglects them and prints only the string.
Q.3. What do you mean by tuple assignment?
Ans. Tuple assignment allows the assignment of values to a tuple of variables on the left side of assignment from the tuple of values on the right side of the assignment.
Q.4. What do you mean by “Lists are mutable”?
Ans. Lists are mutable means that we can change the value of any elements inside the list at any point of time. The element inside the list are accessible with their index value. The index will always start with 0 and end with n-1, if the list contains n elements.
Q5. What do you understand by traversing a list?
Ans. Traversing of the list refers to accessing all the elements or items of the list. Traversing can be done using any conditional statement of Python, but it is preferable to use for loop.
Q.6. What are the different methods used in deleting elements from dictionary?
Ans. Methods used in deleting elements from dictionary are :
- 1. pop(): pop() method removes that item from the dictionary for which the key is provided. It also returns the value of the item.
- 2. popitem(): popitem() method is used to remove or delete and return an arbitrary item from the dictionary.
- 3. clear(): clear() method removes all the items or elements from a dictionary at the same time.
Q.7. What are the two properties of key in the dictionary?
Ans. Properties of key:
- 1. One key in a dictionary cannot have two values, i.e., duplicate keys are not allowed in the dictionary; they must be unique.
- 2. Keys are immutable, i.e., we can use string, integers or tuples for dictionary keys, but cannot use something like [‘key’].
Q8. Why we use functions?
Ans.
- 1. Break up complex problem into small sub-programs.
- 2. Solve each of the sub-problems separately as a function, and combine them together in another function.
- 3. Hide the details and shows the functionality.
Q9. What are mathematical functions? How are they used in Python?
Ans. Python provides us a math module containing most of the familiar and important mathematical functions. A module is a file that contain some predefine Python codes. A module can define functions, classes and variables. It is a collection of related functions grouped together.
Before using a module in Python, we have to import it
For example, to import the math module, we use:
>>> import math
Q10. What are user-defined functions? Give the syntax.
Ans. Python also allows users to define their own functions. To use their own functions in Python, users have to define the functions first; this is known as function definition. In a function definition, users have to define a name for the new function and also the list of the statements that will execute when the function will be called.
Syntax :
Q11. Define the return statement in a function. Give the syntax.
Ans. The return statement is used to exit a function. A function may or may not return a value. If a function returns a value, it is passed back by the return statement as argument to the caller. If it does not return a value, we simply write return with no arguments.
Syntax;
return [expression]
Q12. Define anonymous function.
Ans. The anonymous functions are the functions created using a lambda keyword.
Q13. You have been given a string ‘I live in Cochin. I love pets.’ Divide this string in such a very that the two sentences in it are separated and stored in different variables. Print them.
Ans.
Q14. An email address is provided : hello@python. org. Using tuple assignment, split the username and domain from the email address.
Ans.
Q15. Write a function called sumall that takes any number of arguments and returns their sum.
Ans.
Q16. Write a function called circleinfo which takes the radius of circle as argument and returns the area and circumference of the circle.
Ans.
Q17. Give examples for len, max and min methods.
Ans.
Q.18. Give examples for all, any, len and sorted methods in
dictionary.
Ans.
Q.19. Give the syntax required to convert an integer number into string and a float to an integer.
Ans.
Q20. Write a program to print the calendar for the month of
March 1991.
Ans.
Q21. Write a function which accepts two numbers and returns
their sum.
Ans.
Q22. What are the types of arguments used for calling a function?
Ans. Four types of arguments used for calling a function:
- i. Required argument
- ii. Keyword argument
- iii. Default argument
- iv. Variable length argument
Q23. What is the output of print list[2] when list = [‘abcd’, 2.23,
john’] ?
Ans. john
Q24. What is slicing?
Ans. In Python, we can extract a substring by using a colon inside the square bracket [:]. The resultant substring is a part of the long string.
Q25. What is the use of docstring?
Ans. Docstring command is use to know about a function using triple- quoted string.
Q26. What are local variables and global variables in Python?
Ans.
i. Global variables:
- Global variables are the variables that are defined outside a function body.
- Global variables can be accessed throughout the program body by all functions.
ii. Local variables:
- Local variables are the variables that are defined inside a function body.
- Local variables can be accessed only inside the function in which they are declared.
- When we call a function, the variables declared inside it are brought into scope.
UNIT-4: SIEVE OF ERATOSTHENES & FILE I/0
Q1. What is class variable?
Ans. A variable that is defined in the class and can be used by all the instances of that class is called class variable.
Q.2. Define instance variable.
Ans. A variable that is defined in the method; its scope is only within the object that defines it.
Q3. Define the term instance.
Ans. An object is an instance of the class.
Q4. What do you mean by instantiation?
Ans. The process of creating an object is called instantiation.
Q5. Define function overloading.
Ans. A function defined more than one time with different behaviours is called function overloading.
Q6. What do you mean by methods?
Ans. Methods are the functions defined in the definition of class and are used by various instances of the class.
Q7. How are the objects created in Python? Give an example.
Ans. Objects can be used to access the attributes of the class. The syntax for creating an object in Python is similar to that for calling a
function.
Syntax :
obj_name = class_name()
For example:
Q8. What do you understand by “Objects are mutable” ?
Ans. Objects are mutable means that the state of an object can be changed at any point in time by making changes to its attributes.
Q9. What do you understand by arguments “Instances as return values”?
Ans. The instances of a class can also be returned by a function i.e., function can return the instances or objects.
Q10. Define__dict__,___bases__,__name__built-in class attributes.Give example.
Ans.
__dict__: It displays the dictionary in which the namespace of class is stored.
__name__ : It displays the name of the class.
_bases__: It displays the tuple that contains the base classes, possibly empty. It displays them in the order in which they occur in the base class list.
For example:
Q11. Give the advantage of inheritance.
Ans. The main advantage of inheritance is that the code can be written once in the base class and then reused repeatedly in the subclasses.
Q12. Define subclass.
Ans. The class which inherits the feature of another class is called subclass.
Q13. List the order of file operations in Python.
Ans. The order is as follows:
- 1. Opening a file
- 2. Perform read or write operation
- 3. Closing a file
Q14. Explain any four modes of opening the file.
Ans. Modes of opening the file:
i. r : It opens a file in reading mode. The file pointer is placed at the starting of the file.
ii. r + : It opens the file in both reading and writing mode. The file
pointer is placed at the starting of the file.
iii. w: It opens the file in writing mode. If a file exists, it overwrites the existing file; otherwise, it creates a new file.
iv. w +: It opens the file in both reading and writing mode. If a file exists, it overwrites the existing file; otherwise, it creates a new file.
Q15. Explain the file object attributes in detail.
Ans.
Attribute | Description |
file.closed | It will return true if the file is closed; it will otherwise return false. |
file.mode | It will return the access mode with which the file is opened. |
file.name | It will return name of the file |
file.softspace | It will return false if space explicitly required with print; otherwise it will return true. |
Q16. Give the syntax for reading from a file. What is the work of the readline() function?
Ans. Syntax:
fileobject.read([size])
The count parameter size gives the number of bytes to be read from an opened file. It starts reading from the beginning of the file until the size given. If no size is provided, it ends up reading until the end of the file.
Q17. How are renaming and deleting performed on a file ? Give the syntax for each.
Ans.
Renaming a file: Renaming a file in Python is done with the help of the rename() method. The rename() method is passed with two argument, the current filename and the new filename.
Syntax :
os.rename(current_filename, new_filename)
Deleting a file: Deleting a file in Python is done with the help of the remove() method. The remove() method takes the filename as an argument to be deleted.
Syntax :
os.remove(filename)
Q18. What are the various file positions methods?
Ans. In Python, the tell() method tells us about the current position of the pointer. The current position tells us where reading will starts from at present.
We can also change the position of the pointer with the help of the seek() method. We pass the number of bytes to be moved by the pointer as arguments to the seek() method.
Q19. What are directories?
Ans. If there is a large number of files, then related files are placed in different directories. The directory can be said to be a collection of files
and sub-directories. The module in Python enables us to use various methods to work with directories.
Q20. What are the basic methods performed on directories ?
Ans. Following are the four basic methods that are performed on directories:
- i. mkdir () method (Creating a directory)
- ii. chdir() method (Changing the current directory)
- iii. getcwd () method (Displaying the current directory)
- iv. rmdir () method (Deleting the directory).
Q21. What are user-defined exceptions? Give one example.
Ans. Python allows users to define their own exceptions by creating a new class. Exception needs to be derived, directly or indirectly from exception class.
For example:
>>> class error(Exception)
pass
Q22. Write some built-in exception in Python.
Ans.
- i. AssertionError
- ii. FloatingPointError
- iii. SystemError
- iv. RunTimeError
- v. ZeroDivisionError
Q23. Define ADT interface.
Ans. ADT interface only defines what operations are to be performed
but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called “abstract” because it gives an implementation-independent view.
UNIT-5 : ITERATORS & RECURSION
Q1. What are the properties of recursive functions? ]
Ans. Properties of recursive function:
- 1. The arguments of function change between the recursive calls.
- 2. The change in arguments should be toward a case for which the solution is known and we call it as a base case. There can be more than one base case.
Q2. What are the advantages of recursion?
Ans.
- 1. It requires few variables.
- 2. The programs are easy to implement if the problem has a recursive definition.
Q3. Give some disadvantages of recursion.
Ans.
- 1. Debugging is difficult.
- 2. It is not easy to write the program in a recursive form.
- 3. It can be inefficient as it requires more time and space.
Q4. What are the applications of Tower of Hanoi problem?
Ans.
- 1. The Tower of Hanoi is frequently used in psychological research on problem solving.
- 2. There also exists a variant of this task called Tower of London for neuropsychological diagnosis and treatment of executive functions.
- 3. The Tower of Hanoi is also used as a Backup rotation scheme when performing computer data Backups where multiple tapes/media are involved.
- 4. The Tower of Hanoi is also used as a test by neuropsychologists trying to evaluate frontal lobe deficits.
Q5. What are the advantages and drawbacks of simple search?
Ans: Advantages:
- 1. It is a very simple search and easy to program.
- 2. In the best-case scenario, the item we are searching for may be at the start of the list in which case we get it on the very first try.
Drawbacks :
- 1. Its drawback is that if our list is large, it may take time to go through the list.
- 2. In the worst-case scenario, the item we are searching for may not be in the list, or it may be at the opposite end of the list.
Q6. Write algorithm of simple search.
Ans.
Q7. Give the algorithm for binary search.
Ans
Q8. Define the term sorting.
Ans.
- 1. Sorting is the arrangement of a given list in ascending order or descending order.
- 2. In sorting, searching for an element is very fast.
- 3. Example of sorting in real world are: Contact list in mobile phones, ordering marks before assignment of grades, etc.
Q9. Which operation is used to implement merge sort?
Ans: Merge operation is used to implement merge sort.
Q10. List some sorting algorithm.
Ans.
- 1. Insertion sort
- 2. Selection sort
- 3. Bubble sort
- 4. Merge sort
Q11. What is binary search?
Ans. Binary search is a search algorithm that finds the position of a target value within a sorted list.
Q12. Which method is used to sort a list ?
Ans. Sort() method is used to sort a list.
Q13. What are the possibilities while sorting a list of string?
Ans. Possibilities while sorting a list of string are:
- 1. Sorting in alphabetical/reverse order.
- 2. Based on length of string character.
- 3. Sorting the integer values in list of string.
All Question Paper | AKTU Quantum | solution of question paper
Python Programming Important Links:
Label | Link |
---|---|
Subject Syllabus | Syllabus |
Short Questions | Short-question |
Important Unit-1 | Unit-1 |
Important Unit-2 | Unit-2 |
Important Unit-3 | Unit-3 |
Important Unit-4 | Unit-4 |
Important Unit-5 | Unit-5 |
Question paper – 2021-22 | 2021-22 |
AKTU Important Links | Btech Syllabus
Link Name | Links |
---|---|
Btech AKTU Circulars | Links |
Btech AKTU Syllabus | Links |
Btech AKTU Student Dashboard | Student Dashboard |
AKTU RESULT (One VIew) | Student Result |
Important Links-Btech (AKTU) | Python Programming syllabus
Label | Links |
---|---|
Btech Information | Info Link |
Btech CSE | CSE-LINK |
Quantum-Page | Link |
Python Programming Syllabus | Python Programming Syllabus |
5 thoughts on “Python Programming Important Short Questions With Answer – Btech AKTU”