Viva Questions
Viva Questions
1. What is Python?
Numbers
String
List
Tuple
Dictionary
Ans: It will print characters starting from 3rd to 5th. Output would be llo.
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!'?
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].
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.
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).
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').
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.
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.
Ans: int(x [,base]) - Converts x to an integer. base specifies the base if x is a string.
Ans: long(x [,base] ) - Converts x to a long integer. base specifies the base if x is a string.
Ans: break statement − Terminates the loop statement and transfers execution to the
statement immediately following the loop.
Ans: continue statement − Causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating.
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.
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
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.
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.
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?
54. How will you change case for all letters in string?
Ans: title() − Returns "titlecased" version of string, that is, all words begin with uppercase
and the rest are lowercase.
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]
Ans: True
68. How will you get the max valued item of a list?
Ans: max(list) − Returns item from the list with max value.
74. Write a program in Python to reverse a string without using inbuilt function reverse
string?
def string_reverse(str1):
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)
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.
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
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.
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()
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
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.
Star topology consists of a central hub that connects to nodes. This is one of the easiest to
setup and maintain.
One major disadvantage of star topology is that once the central hub or switch get damaged,
the entire network becomes unusable.
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.
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
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.