0% found this document useful (0 votes)
4 views2 pages

Python Programming Challenges and Solutions

Uploaded by

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

Python Programming Challenges and Solutions

Uploaded by

Rathees P G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

####################Protocol Testing#########################

[Link] of two numbers without using temp ?


[Link] a program for Palindrome
[Link] duplicate elements in a list and print including duplicate also
[Link] find a cube root in function method
[Link] a log file
/var/log/syslog/
27oct---

[Link] want to grep with date=27oct &module=[Link] in function method,and output is


expected as filter('27oct','[Link]')-->['my-message-0','my-message-1'...'my-
message-5']
[Link] a string want to print reverselly with a words(not in chars)
[Link] a given sring want to identify only digits(numbers)
[Link] a program for dictionary and can segricate the values based on data types
[Link] a program to convert dictionary in to a list
[Link] a program for at a time multiple routers reload
[Link] is use of lambda function
[Link] a paragraph want to grep first qp chars if space is ended need to print with
previous chars
[Link] my system ram size is 2gb,but file size is 2TB,how to read through the file
handling?
[Link] a linux want to login and execute ifconfig and need to grep ip [Link] is
assigned in any of interface ?
[Link] a string want to print mac address alone?
[Link] a program shall we use else in while and for loop?
[Link] a given list want to print second largest number ?
[Link] a list want to delete by "elements(values)" directly?
[Link] is generator and decorator
[Link] =[0,1,2,...100]
Print two different list , one with only even number and other with only odd
numbers

[Link] a given list list1=[1,2,3,'all','bob',foo',4] Print numbers in one list and


strings in another list.
[Link] between set and list.

1.)Write a program using lib file and follow teamplate setup,test and teardown.
2.)Try/Except clause. How to do handle all exceptions. what is meant by user
defined exception ?
3.)Write the above program using class
4.)What is class, what is object, use of main function
5.)What is use of self in class
6.)Dictionary advantages and disadvantages (which one replace dictionary)
7.)Reverse the word --- "DHANABAL IS MY NAME" (Reverse it)
8.)What is meant by static/class variable
9.)What is meant by class members/class methods/static method/instance method
10.)what is difference between list and tuple
11.)a = (1,2,3). Add last element to tuple. Add elements in between tuple.
12.)what is meant by lambda ? whatis filter,map,reduce ? write programs for
filter,map,reduce
13.)list comprehension, dictionary comprehension --- complete
14.)Memory management in python
15.)How to append dictionary to another dictionary ?
16.)What is meant by encapsulation ? what is meant by abstract class ?
17.)Inheritance --- complete, what is meant by mutiple inheritance ? what is MRO ?
18.)Polymorphism --- Method overriding, Method overloading, operator overloading
--- complete
19.)Write a program --- list with hundreds of strings ("Suman_Raju_Ramu",....)
where we should remove underscore and make trailing letter captialize for all
strings using decorator and pass the output to another function.
20.)write a program to sort the list based on surname
21.)*args and **kwargs
22.)use of zip command in python
23.)encapsulation in python
24.)Abstract class in python
25.)how to call same method (2 methods with same name in single class) ?
26.)reverse list using logics (using for loop and range function)
27.)write a program to select unmatched numbers in 2 different lists
28.)shallow copy and deep copy
29.)GIT commands
30.)what is meant by smoke testing ?
31.)Linux commands to find file, search process, kill process
32.)Regex commands in python
33.)grep ip address using python
34.)write fibonaci program in python
35.)what is recuersive function ?
36.)what is iterator and generator --- complete
37.)what is magic methods ? --- complete
38.)use of __init__ and main() functions in python
39.)use of tuple() in real time
40.)use of static methods and class methods real time
41.)find even number without using modulus operator
42.)is operator and in operator in python
43.)how to login into device (ssh function) ?
44.)what are the files available in datastore for virtual machines ?
45.)what is the size of vmdk files ?
46.)what is meant by VMDK files ?
47.)singly linked list, how to reverse singly linked list , how to remove middle
node in linked list ?
48.)find subset of string
49.)find out the second largest number in the list
50.)remove trailing zeros from the string
51.)difference between sort(),sorted(). Difference between reverse() and reversed()
functions
52.)regex to search uppercase in string
53.)regex to find interface details in the string
54.)write a program to where input is (abc$%d) and output should be (dcb$%a) using
classmethod
55.)write a program to create meeting
56.)what is golden regression testing
57.)How to get proper number in python ?
58.)Use of __init__.py file in python
59.)how python will know the

Common questions

Powered by AI

A shallow copy of an object creates a new object but inserts references to the original items, not the objects themselves. In contrast, a deep copy duplicates everything and therefore creates a fully independent copy of the original, including nested objects. Practically, this means that modifying a shallow copy can reflect changes in the original if the objects are mutable; however, changes to a deep copy don't affect the original structure. For example, modifying elements of a list within a shallow copy affects the original list, whereas a deep copy would not reflect those changes .

Decorators in Python extend or alter the behavior of functions or methods without changing their code. They are higher-order functions that take another function as an argument, enhancing it with additional functionality such as logging, access control, or memoization. A classic example is using the @decorator syntax to wrap a function, thus providing reuse and modularity. For instance, a decorator could log the entry and exit points of a function, aiding debugging by capturing runtime behavior .

Lambda functions in Python provide a compact way to create small, anonymous functions at runtime. They are primarily useful in situations that require simple operations, such as sorting lists with custom criteria using the 'sort()' method or filtering data with the 'filter()' function. They are often used in functional programming paradigms where short-lived functions are utilized for single-expression operations. Moreover, their inline nature makes them particularly suitable for use with map(), reduce(), and filter() functions, allowing for elegant and concise code .

In Python, *args and **kwargs allow functions to accept variable numbers of positional and keyword arguments, respectively. *args is used to pass a non-keyworded, variable-length argument list, and **kwargs allows passing keyworded arguments—making functions highly flexible. Common use cases include functions requiring unpredictable input sizes, such as logging or printing debug statements. They also facilitate better integration with frameworks where callbacks and event handlers demand flexibility in their argument lists .

Sets and lists in Python serve different purposes. Lists maintain order and allow duplicate elements, making them suitable for collections where order matters or duplicates are necessary. Conversely, sets are unordered collections of unique elements, suitable for operations involving mathematical set theory like union, intersection, and difference. Lists are preferable when ordering is crucial or when performance isn’t the main concern, while sets are beneficial when uniqueness and fast membership testing, provided by their hash tables, are priorities .

Magic methods in Python, often recognizable by double underscores at the beginning and end of names, like __init__, __str__, or __add__, enable different object-oriented programming paradigms such as operator overloading. These methods automatically trigger certain behavior when class instances interact in specific ways, turning objects into fully functional, customized types. They deepen class capabilities, allowing for beautiful and intuitive interaction patterns when building complex systems .

Encapsulation in Python restricts direct access to an object’s data, which can prevent the accidental modification of attributes. It is typically achieved by defining attributes as private using an underscore prefix. Abstract classes, on the other hand, define a template for future classes, promoting code reusability and uniformity without implementing the detailed functionality. Both concepts support the object-oriented programming paradigm by promoting modular and secure code design through data hiding and implementation sharing, enhancing the robustness and flexibility of the system .

Polymorphism in Python allows objects of different classes to be treated as objects of a common superclass. It supports the 'one interface, many implementations' concept by allowing the same method to behave differently based on the calling object’s class. This is primarily achieved through method overriding and operator overloading. Polymorphism is fundamental in object-oriented design, facilitating code generalization and reuse, thereby leading to systems that are easier to scale and modify .

The zip() function in Python creates an iterator that aggregates elements from two or more iterables. It is commonly used to pair data like columns from tables or matching indices from separate datasets. For instance, zip() can effectively pair names with their corresponding scores for easier manipulation and analysis, enabling the simultaneous handling of multiple related sequences, enhancing code readability and performance .

The __init__ method in Python serves as the constructor for a class, initializing the object's state and binding attributes to their initial values. It is called automatically when a new object of a class is instantiated. The main() function, on the other hand, is a conventionally used function that serves as the entry point of execution in scripts. It is often invoked conditionally via 'if __name__ == "__main__":' to differentiate between executing code directly and importing it into another module .

You might also like