0% found this document useful (0 votes)
5 views11 pages

Viva Questions

The document contains a comprehensive list of VIVA questions and answers covering various aspects of Python programming, including its features, data types, and functionalities. It also includes practical examples and explanations of concepts such as lists, tuples, dictionaries, and string manipulation. Additionally, it touches on Python libraries like Scikit-learn and frameworks like Django, along with basic programming tasks and file handling.

Uploaded by

szbharat3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Viva Questions

The document contains a comprehensive list of VIVA questions and answers covering various aspects of Python programming, including its features, data types, and functionalities. It also includes practical examples and explanations of concepts such as lists, tuples, dictionaries, and string manipulation. Additionally, it touches on Python libraries like Scikit-learn and frameworks like Django, along with basic programming tasks and file handling.

Uploaded by

szbharat3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

VIVA QUESTIONS (COVERING THE ENTIRE SYLLABUS)

Note: These questions are good to revise for theory also.

1. What is Python?

Ans: Python is a high-level, interpreted, interactive and object-oriented scripting language.


Python is designed to be highly readable. It uses English keywords frequently where
as other languages use punctuation, and it has fewer syntactical constructions than
other languages.

2. Name some of the features of Python.

Ans: Following are some of the salient features of python −

 It supports functional and structured programming methods as well as OOP.


 It can be used as a scripting language or can be compiled to byte-code for building
large applications.
 It provides very high-level dynamic data types and supports dynamic type checking.
 It supports automatic garbage collection.
 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

3. Is python a case sensitive language?

Ans: Yes! Python is a case sensitive programming language.

4. What are the supported data types in Python?

Ans: Python has five standard data types −

 Numbers
 String
 List
 Tuple
 Dictionary

5. What is the output of print str if str = 'Hello World!'?

Ans: It will print complete string. Output would be Hello World!.

6. What is the output of print str[0] if str = 'Hello World!'?

Ans: It will print first character of the string. Output would be H.

7. What is the output of print str[2:5] if str = 'Hello World!'?

Ans: It will print characters starting from 3rd to 5th. Output would be llo.

8. What is the output of print str[2:] if str = 'Hello World!'?


Ans: It will print characters starting from 3rd character. Output would be llo World!.

9. What is the output of print str * 2 if str = 'Hello World!'?

Ans: It will print string two times. Output would be Hello World!Hello World!

10. What is the output of print str + "TEST" if str = 'Hello World!'?

Ans: It will print concatenated string. Output would be Hello World!TEST.

11. What is the output of print list if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

Ans: It will print complete list. Output would be ['abcd', 786, 2.23, 'john',
70.200000000000003].

12. What is the output of print list[0] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

Ans: It will print first element of the list. Output would be abcd.

13. What is the output of print list[1:3] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

Ans: It will print elements starting from 2nd till 3rd. Output would be [786, 2.23].

14. What is the output of print list[2:] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

Ans: It will print elements starting from 3rd element. Output would be [2.23, 'john',
70.200000000000003].

15. What is the output of print tinylist * 2 if tinylist = [123, 'john']?

Ans; It will print list two times. Output would be [123, 'john', 123, 'john'].

16. What is the output of print list1 + list2, if list1 = [ 'abcd', 786 , 2.23, 'john', 70.2 ] and ist2
= [123, 'john']? What are tuples in Python?

Ans: A tuple is another sequence data type that is similar to the list. A tuple consists of a
number of values separated by commas. Unlike lists, however, tuples are enclosed within
parentheses.

17. What is the difference between tuples and lists in Python?

Ans: The main differences between lists and tuples are − Lists are enclosed in brackets
( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses
( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.

18. What is the output of print tuple if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )?

Ans: It will print complete tuple. Output would be ('abcd', 786, 2.23, 'john',
70.200000000000003).
19. What is the output of print tuple[0] if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )?

Ans: It will print first element of the tuple. Output would be abcd.

20. What is the output of print tuple[1:3] if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )?

Ans: It will print elements starting from 2nd till 3rd. Output would be (786, 2.23).

21. What is the output of print tuple[2:] if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )?

Ans: It will print elements starting from 3rd element. Output would be (2.23, 'john',
70.200000000000003).

22. What is the output of print tinytuple * 2 if tinytuple = (123, 'john')?

Ans: It will print tuple two times. Output would be (123, 'john', 123, 'john').

23. What is the output of print tuple + tinytuple if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
and tinytuple = (123, 'john')?

Ans: It will print concatenated tuples. Output would be ('abcd', 786, 2.23, 'john',
70.200000000000003, 123, 'john').

24. What are Python's dictionaries?

Ans: Python's dictionaries are kind of hash table type. They work like associative arrays or
hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any
Python type, but are usually numbers or strings. Values, on the other hand, can be any
arbitrary Python object.

25. How will you create a dictionary in python?

Ans: Dictionaries are enclosed by curly braces ({ }) and values can be assigned and
accessed using square braces ([]).

dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}

26. How will you get all the keys from the dictionary?

Ans: Using dictionary.keys() function, we can get all the keys from the dictionary object.

print dict.keys() # Prints all the keys


27. How will you get all the values from the dictionary?
Ans: Using dictionary.values() function, we can get all the values from the dictionary
object.

print dict.values() # Prints all the values


28. How will you convert a string to an int in python?

Ans: int(x [,base]) - Converts x to an integer. base specifies the base if x is a string.

29. How will you convert a string to a long in python?

Ans: long(x [,base] ) - Converts x to a long integer. base specifies the base if x is a string.

30. How will you convert a string to a float in python?

Ans: float(x) − Converts x to a floating-point number.

31. How will you convert a object to a string in python?

Ans: str(x) − Converts object x to a string representation.

32. How will you create a dictionary using tuples in python?

Ans: dict(d) − Creates a dictionary. d must be a sequence of (key,value) tuples.

33. How will you convert an integer to a character in python?

Ans: chr(x) − Converts an integer to a character.

34. What is the purpose break statement in python?

Ans: break statement − Terminates the loop statement and transfers execution to the
statement immediately following the loop.

35. What is the purpose continue statement in python?

Ans: continue statement − Causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating.

36. What is the purpose pass statement in python?

Ans: pass statement − The pass statement in Python is used when a statement is required
syntactically but you do not want any command or code to execute.

37. How can you get a random number in python?


Ans: random() − returns a random float r, such that 0 is less than or equal to r and r is less
than 1.

38. How will you set the starting value in generating random numbers?

Ans: seed([x]) − Sets the integer starting value used in generating random numbers. Call
this

39. How will you capitalizes first letter of string?

Ans: capitalize() − Capitalizes first letter of string.

40. How will you check in a string that all characters are alphanumeric?

Ans: isalnum() − Returns true if string has at least 1 character and all characters are
alphanumeric and false otherwise.

41. How will you check in a string that all characters are digits?

Ans: isdigit() − Returns true if string contains only digits and false otherwise.

42. How will you check in a string that all characters are in lowercase? How will you check
in a string that all characters are numerics?

Ans: isnumeric() − Returns true if a unicode string contains only numeric characters and
false otherwise.

43. How will you check in a string that all characters are whitespaces?

Ans: isspace() − Returns true if string contains only whitespace characters and false
otherwise.

44. How will you check in a string that it is properly titlecased?

Ans: istitle() − Returns true if string is properly "titlecased" and false otherwise.

45. How will you check in a string that all characters are in uppercase?

Ans: isupper() − Returns true if string has at least one cased character and all cased
characters are in uppercase and false otherwise.

46. How will you merge elements in a sequence?

Ans: join(seq) − Merges (concatenates) the string representations of elements in sequence


seq into a string, with separator string.

47. How will you get the length of the string?

Ans: len(string) − Returns the length of the string.


48. How will you get a space-padded string with the original string left-justified to a total of
width columns? How will you convert a string to all lowercase?

Ans: lower() − Converts all uppercase letters in string to lowercase.

49. How will you remove all leading whitespace in string?

Ans: lstrip() − Removes all leading whitespace in string.

50. How will you get the max alphabetical character from the string?

Ans: max(str) − Returns the max alphabetical character from the string str.

51. How will you get the min alphabetical character from the string?

Ans: min(str) − Returns the min alphabetical character from the string str.

52. How will you replaces all occurrences of old substring in string with new string?

Ans: replace(old, new [, max]) − Replaces all occurrences of old in string with new or at
most max occurrences if max given.

53. How will you remove all leading and trailing whitespace in string?

Ans: strip([chars]) − Performs both lstrip() and rstrip() on string.

54. How will you change case for all letters in string?

Ans: swapcase() − Inverts case for all letters in string.

55. How will you get titlecased version of string?

Ans: title() − Returns "titlecased" version of string, that is, all words begin with uppercase
and the rest are lowercase.

56. How will you convert a string to all uppercase?

Ans: upper() − Converts all lowercase letters in string to uppercase.

57. How will you check in a string that all characters are decimal?

Ans: isdecimal() − Returns true if a unicode string contains only decimal characters and
false otherwise.

58. What is the difference between del() and remove() methods of list?

Ans: To remove a list element, you can use either the del statement if you know exactly
which element(s) you are deleting or the remove () method if you do not know.
59. What is the output of len([1, 2, 3])?
Ans: 3.
60. What is the output of [1, 2, 3] + [4, 5, 6]?

Ans: [1, 2, 3, 4, 5, 6]

61. What is the output of ['Hi!'] * 4?

Ans: ['Hi!', 'Hi!', 'Hi!', 'Hi!']

62. What is the output of 3 in [1, 2, 3]?

Ans: True

63. What is the output of for x in [1, 2, 3]: print x?


Ans: 1
2
3
64. What is the output of L[2] if L = [1,2,3]?

Ans: 3, Offsets start at zero.

65. What is the output of L[-2] if L = [1,2,3]?

Ans: 1, Negative: count from the right.

66. How will you compare two lists?

Ans: cmp(list1, list2) − Compares elements of both lists.

67. How will you get the length of a list?

Ans: len(list) − Gives the total length of the list.

68. How will you get the max valued item of a list?

Ans: max(list) − Returns item from the list with max value.

69. How will you remove last object from a list?

Ans: list.pop( ) − Removes last object or obj from list.

70. How will you remove an object from a list?

Ans: list.remove(obj) − Removes object obj from list.

71. How will you reverse a list?

Ans: list.reverse() − Reverses objects of list in place.


72. How will you sort a list?

Ans: list.sort([func]) − Sorts objects of list, use compare func if given.

73. Name the python Library used for Machine learning.

Ans: Scikit-learn python Library used for Machine learning

74. Write a program in Python to reverse a string without using inbuilt function reverse
string?

Ans: Program to reverse a string in given below −

def string_reverse(str1):

rev_str = ' '


index = len(str1) #defining index as length of string.
while(index>0):
rev_str = rev_str + str1[index-1]
index = index-1
return(rev_str)

print(string_reverse('1tniop'))

First we declare a variable to store the reverse string. Then using while loop and indexing of
string (index is calculated by string length) we reverse the string. While loop starts when
index is greater than zero. Index is reduced to value 1 each time. When index reaches zero we
obtain the reverse of string.

75. Write a program to test whether the number is in the defined range or not?

Ans: Program is −

def test_range(num):
if num in range(0, 101):
print(''%s is in range''%str(num))
else:
print(''%s is not in range''%str(num))

Output −

test_range(101)

101 is not in the range

76. Which of the following command is used to open a file “c:\temp.txt”


for writing in binary format only?
Ans: outfile = open(“c:\\temp.txt”, “wb”)

77. Which command is used to open a file in Python ?

Ans: infile = open(“c:\temp.txt”)


78. Which function do you use to write data in the binary format?
Ans: dump

79. What is Django?


Django is a free and open source web application framework, written in Python. A web framework is a set of
components that helps you to develop websites faster and easier
80. Name any two options to export data using Django in Python.

Ans: (1) export data to a .csv file using Python’s csv module;

(2) export data to a .xls file using a third-party module named xlwt.

81. What is MVC framework?


Ans: MVC is model view controller where a user requests to view a page by entering a
URL.
 The Controller receives that request.
 It uses the Models to retrieve all of the necessary data, organizes it, and sends it
off to the…
 View, which then uses that data to render the final webpage presented to the the
user in their browser

82. What is MySQLdb?


MySQLdb is an interface for connecting to a MySQL database server from Python. It
implements the Python Database API v2.0 and is built on top of the MySQL C API
83. Define Primary Key:

A candidate key which uniquely identifies all other attributes values in any given row. It cannot
contain null entries. Consider table Employee has following fields EmpNo, Empname,
designation,salary where Empno acts as primary key

84. Define foreign key


Foreign Key: An attribute or combination of attributes in one table which is primary key in another
table .For ex: Consider two tables name as Customer and Product
What is cyber law.
Ans: Cyberlaw is the area of law that deals with the Internet's relationship to
technological and electronic elements, including computers, software, hardware
and information systems (IS).Cyberlaw is also known as Internet Law.

85. what is IT Act 2000

Ans: The Information Technology Act 2000 (ITA-2000) (IT ACT) is an Act of the
Indian Parliament (No 21 of 2000) notified on October 17, 2000 which regulates the rules
and regulations followed on internet.

86. Name two modules required to perform data visualisation in Python


Matplotlib
Numpy

87. Name any two functions which are commonly used to calculate time of code ?

Ans: There are two import functions which are commonly used to calculate time of the code
namely:

timeit.default_timer()
timeit.timeit()

88. What is peer to peer network?

Ans Peer to peer are networks that does not reply on a server. All PCs on this network act as
individual workstations
89. What are the two types of topology.
Ans Star Topology
Bus Topology

90. What are firewalls?

Firewalls serve to protect an internal network from external attacks. These external threats
can be hackers who want to steal data or computer viruses that can wipe out data in an
instant. It also prevents other users from external networks from gaining access to the private
network.

91. Describe star topology

Star topology consists of a central hub that connects to nodes. This is one of the easiest to
setup and maintain.

92. What are gateways?

Gateways provide connectivity between two or more network segments. It is usually a


computer that runs the gateway software and provides translation services. This translation is
a key in allowing different systems to communicate on the network.

93. What is the disadvantage of a star topology?

One major disadvantage of star topology is that once the central hub or switch get damaged,
the entire network becomes unusable.

94. What is the difference between a hub and a switch?

A hub acts as a multiport repeater. However, as more and more devices connect to it, it would
not be able to efficiently manage the volume of traffic that passes through it. A switch
provides a better alternative that can improve the performance especially when high traffic
volume is expected across all ports.
95. What is IPv6?

IPv6 , or Internet Protocol version 6, was developed to replace IPv4. At present, IPv4 is being
used to control internet traffic, butis expected to get saturated in the near future. IPv6 was
designed to overcome this limitation.

96. What is phishing?

Phishing is a common type of scam used to elicit confidential, lucrative, and/or sensitive
information. Most often, phishing comes in the form of emails appearing to be sent from a
trustworthy company or person but containing malicious links, requests for information, or
harmful attachments

97. What is the difference between spam and phishing?

Spam is electronic junk mail or, more broadly, unsolicited sales emails. Spam differs from
phishing because spam emails will not request sensitive or confidential information; rather
they will attempt to sell you an item, service, or subscription.

98. What are the risks associated with using public Wi-Fi?
Ans: cyber attacks that deploy data-stealing malware in
your system, deceiving and dangerous Man in the Middle
attacks (that could lead to all sorts of infections) and
many, many more.
99. Name any two popular error detection techniques?
Ans Popular techniques are: (write any two)
•Simple Parity check
•Two-dimensional Parity check
100. What is client server architecture?
Ans. To designated a particular node which is well known and fixed
address, to provide a service to the network as a whole. The node
providing the service is known as the server and the nodes that use that
services are called clients of that server. This type of network is called
Client-Server Architecture.

You might also like