[TY BSC CS] PYTHON MOST IMPORTANT QUESTIONS FOR SEM 5 IN 2023 | PYTHON IMP QUESTIONS FOR COMPUTER SCIENCE SEMESTER FIVE

[TY BSC CS] PYTHON MOST IMPORTANT QUESTIONS FOR SEM 5 IN 2023 | PYTHON IMP QUESTIONS FOR COMPUTER SCIENCE SEMESTER FIVE


[TY BSC CS] PYTHON MOST IMPORTANT QUESTIONS FOR SEM 5 IN 2023 | PYTHON IMP QUESTIONS FOR COMPUTER SCIENCE SEMESTER FIVE



Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.

Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library

Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0. Python 2.0 was released in 2000 and introduced new features such as list comprehensions, cycle-detecting garbage collection, reference counting, and Unicode support. Python 3.0, released in 2008, was a major revision not completely backward-compatible with earlier versions. Python 2.7.18, released in 2020, was the last release of Python 2.

Download October 2022 TY BCS cs Sem-5 Question Paper 



Python consistently ranks as one of the most popular programming languages

here is PYTHON MOST IMPORTANT QUESTIONS FOR SEM 5 IN 2023

 1) What is a file? How to read and write to a file?

A file is a information or data which permanently stored in computer storage devices that 

can access any time.

In python, there are some inbuilt functions exist, to read and write to a file.

write(): method is used to write/ insert data into the file.

Open(‘filename’, ‘r’) : method is used to open file in read format.


2) Explain the frozen set with an example.

  • i) The frozen sets are the immutable form of the normal sets, i.e., the items of the frozen 
  • set cannot be changed and therefore it can be used as a key in the dictionary.
  • ii) The elements of the frozen set cannot be changed after the creation.
  • iii) We cannot change or append the content of the frozen sets by using the methods like add() or remove().
  • iv) The frozenset() method is used to create the frozenset object.
  • v) The iterable sequence is passed into this method which is converted into the frozen set 
  • as a return type of the method.


Ex:

Frozenset = frozenset([1,2,3,4,5]) 

print(type(Frozenset)) 

print("\nprinting the content of frozen set...") 

for i in Frozenset: 

print(i); 

Frozenset.add(6)


[TY BSC CS] PYTHON MOST IMPORTANT QUESTIONS FOR SEM 5 IN 2023 | PYTHON IMP QUESTIONS FOR COMPUTER SCIENCE SEMESTER FIVE

3) Define text and binary files with an example.

  • i) A text file consists of human readable characters, which can be opened by any text editor.
  • ii)Binary files are made up of non-human readable characters and symbols, which require  specific programs to access its contents.


4) Give the purpose of the match function.

Python's re.match() function finds and delivers the very first appearance of a regular 

expression pattern.


5) Explain RegEx.

A regular expression is a set of characters with highly specialized syntax that we can use 

to find or match other characters or groups of characters.

In short, regular expressions, or Regex, are widely used in the UNIX world.

The re-module in Python gives full support for regular expressions of Pearl style.

The re module raises the re.error exception whenever an error occurs while implementing 

or using a regular expression.


6) Write the use of tell() and seek() functions.

It returns the current position of the file pointer within the file.

Python provides us the seek() method which enables us to modify the file pointer 

position externally.


7) Explain Call by value and call by reference in python.

Call by value:

  • i) In this particular parameter passing method, the values of the actual parameters copy into the function’s formal parameters. It stores both types of parameters in different memory locations. Thus, if one makes any changes inside the function- it does not show on the caller’s actual parameters.
  • ii)This method passes a copy of an actual argument to the formal argument of any called function.

Call by Reference

  • iii) In this case, both the formal and actual parameters refer to a similar location. It means that if one makes any changes inside the function, it gets reflected in the caller’s actual parameters.
  • iv) This method passes the address or location of the actual arguments to the formal arguments of any called function. It means that by accessing the actual argument’s addresses.

READ ALSO: Most Usefull Computer Keyboard shortcuts for you

1k views in just 10 min on YouTube 2023 


8) Explain string methods with examples.


Method Description

  1. capitalize(): Converts the first character to upper case
  2. casefold(): Converts string into lower case
  3. center(): Returns a centered string
  4. count(): Returns the number of times a specified value occurs in a string
  5. encode(): Returns an encoded version of the string
  6. endswith(): Returns true if the string ends with the specified value.


9) Explain Anonymous function with an example.

  • i) Python Lambda Functions are anonymous function means that the function is without a name.
  • ii)As we already know that the def keyword is used to define a normal function in Python.
  • iii) Also, the lambda keyword is used to define an anonymous function in Python.


Ex.,

str1 = 'GeeksforGeeks'

# lambda returns a function object

rev_upper = lambda string: string.upper()[::-1]

print(rev_upper(str1))



10) Define List and Explain list methods with an example.

  • i) A list in Python is used to store the sequence of various types of data.
  • ii)The list is a sequence data type which is used to store the collection of data.
  • iii) Python lists are mutable types; it means we can modify its element after it is created. 


Method Description


  1. append(): Used for appending and adding elements to the end of the List.
  2. copy(): It returns a shallow copy of a list
  3. clear(): This method is used for removing all items from the list.
  4. count() :This methods count the elements
  5. extend(): Adds each element of the iterable to the end of the List
  6. index() Returns the lowest index where the element appears.
  7. insert(): Inserts a given element at a given index in a list.
  8. pop(): Removes and returns the last value from the List or the given index value.


11) What is a dictionary? Explain all the dictionary methods with an example?

  • i) Python Dictionary is used to store the data in a key-value pair format.
  • ii) The dictionary is the data type in Python, which can simulate the real-life data arrangement where some specific value exists for some particular key.
  • iii) It is a mutable data-structure.
  • iv) The dictionary is defined into element Keys and values.
  • v) Keys must be a single element


Method Description


  1. clear(): Removes all the elements from the dictionary
  2. copy(): Returns a copy of the dictionary
  3. fromkeys(): Returns a dictionary with the specified keys and value
  4. get(): Returns the value of the specified key
  5. items(): Returns a list containing a tuple for each key value pair
  6. keys() :Returns a list containing the dictionary's keys
  7. pop(): Removes the element with the specified key
  8. popitem() : Removes the last inserted key-value pair
  9. setdefault(): Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
  10. update(): Updates the dictionary with the specified key-value pairs
  11. values(): Returns a list of all the values in the dictionary



12) What is the local and global scope of variables in python? Explain the different 
scenarios with an example snippet.



13) Explain tuples with an example.


  • i) Tuple is a collection of Python objects much like a list.
  • ii) The sequence of values stored in a tuple can be of any type, and they are indexed by integers.
  • iii) Values of a tuple are syntactically separated by ‘commas’.


Ex.,

Tuple1 = ('Geeks', 'For', ‘Geeks’)

print(Tuple1)



14) Show how try…except blocks is used for exception handling in Python with 
examples.


try:

print(x)

except NameError:

print("Variable x is not defined")

except:

print("Something else went wrong")



15) Explain set operations in detail with an example.

 

set1 = {1, 2, 3, 4}

set2 = {2, 5, 4, 6}

set1.add(4)

set2.clear()

x = set1.copy(set2)

y = set1.difference(set2)

a = set1.union(set2)

z = set1.intersection(set2)

set1.pop()

set1.remove()



16) Design a python program which will throw an exception if the value entered by the 
user is less than zero.


17) Define:

i. Data type

Data type is a type of data stored into the variable. Python is a dynamically typed 

language; hence we do not need to define the type of the variable while declaring it.


ii. Function

A function is a block of code which only runs when it is called. You can pass data, 

known as parameters, into a function. A function can return data as a result.


18) Explain the need for Unicodes. 

Unicode provides a unique way to define every character in every spoken language 

of the world by assigning it a unique number.

The Unicode standard is maintained by the Unicode Consortium and defines more 

than 1,40,000 characters from more than 150 modern and historic scripts along with 

emoji.

Unicode can be defined with different character encoding like UTF-8, UTF-16, UTF-

32, etc.

Among these UTF-8 is the most popular as it is used in over 90% of websites on the 

World Wide Web as well as on most modern Operating systems like Windows.


ALSO READ :

 Simple 30 Computer science project topic ideas for begging students.

What is Content Marketing




PYTHON IMP QUESTIONS FOR COMPUTER SCIENCE SEMESTER FIVE

19) Explain the match function in detail

Python's re.match() function finds and delivers the very first appearance of a regular 
expression pattern.


In Python, the RegEx Match function solely searches for a matching string at the 
beginning of the provided text to be searched.
The matching object is produced if one match is found in the first line.
If a match is found in a subsequent line, the Python RegEx Match function gives 
output as null.


Examine the implementation for the re.match() method in Python.
The expressions ".w*" and ".w*?" will match words that have the letter "w," and 
anything that does not have the letter "w" will be ignored.


The for loop is used in this Python re.match() illustration to inspect for matches for 
every element in the list of words.

Post a Comment

0 Comments