Premium Employer

Infosys

3.7
based on 36.3k Reviews
Filter interviews by

Interview Questions and Answers

Updated 13 Aug 2024
Popular Designations

Q1. what is list comprehension? write some sample code? what is use of it?

Ans.

List comprehension is a concise way to create lists in Python by iterating over an existing list or iterable.

  • List comprehension is more concise and readable than traditional loops.

  • It can be used to filter elements, perform operations on elements, or create new lists based on existing ones.

  • Example: squares = [x**2 for x in range(10)]

  • Example: even_numbers = [x for x in range(10) if x % 2 == 0]

Add your answer

Q2. what is dictionary? is this accept duplicate or not?

Ans.

A dictionary in Python is a collection of key-value pairs. It does not accept duplicate keys.

  • A dictionary is created using curly braces {}

  • Keys in a dictionary must be unique, but values can be duplicated

  • Example: my_dict = {'name': 'John', 'age': 30, 'city': 'New York'}

Add your answer

Q3. what is generator? write sample code

Ans.

A generator in Python is a function that returns an iterator object which can be iterated over to generate values lazily.

  • Generators are created using a function with 'yield' keyword instead of 'return'.

  • They allow for efficient memory usage as they generate values on the fly.

  • Generators are useful for generating large sequences of data without storing them in memory.

  • Example: def my_generator(): for i in range(5): yield i

  • Example: gen = my_generator() for value in gen: print(valu...read more

Add your answer

Q4. what are the main principles of oops?

Ans.

Main principles of OOP include encapsulation, inheritance, polymorphism, and abstraction.

  • Encapsulation: Bundling data and methods that operate on the data into a single unit (class). Example: Class with private attributes and public methods.

  • Inheritance: Ability to create a new class (derived class) from an existing class (base class), inheriting its attributes and methods. Example: Subclass 'Dog' inheriting from superclass 'Animal'.

  • Polymorphism: Ability for objects of differe...read more

Add your answer
Discover null interview dos and don'ts from real experiences

Q5. write code of fibonacci series?

Ans.

Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones.

  • Initialize variables for the first two numbers in the series (0 and 1)

  • Use a loop to calculate the next number by adding the previous two numbers

  • Continue the loop until the desired number of terms is reached

Add your answer

Q6. what is aws lambda function

Ans.

AWS Lambda is a serverless computing service provided by Amazon Web Services.

  • Serverless computing service

  • Allows running code without provisioning or managing servers

  • Automatically scales based on incoming traffic

  • Supports multiple programming languages like Python, Node.js, Java, etc.

  • Pay only for the compute time consumed

Add your answer

Q7. what is decorator?

Ans.

Decorator is a design pattern in Python that allows adding new functionality to an existing object without modifying its structure.

  • Decorators are functions that take another function as an argument and extend its behavior without modifying it directly.

  • They are commonly used to add logging, timing, caching, or authentication to functions.

  • Decorators use the @ symbol followed by the decorator name above the function definition.

  • Example: @decorator_name def function_name(): pass

Add your answer

Q8. difference between list and tuple

Ans.

List is mutable, tuple is immutable in Python.

  • List can be modified after creation, tuple cannot.

  • List uses square brackets [], tuple uses parentheses ().

  • List is used for dynamic data, tuple for fixed data.

  • Example: list_example = [1, 2, 3], tuple_example = (4, 5, 6)

Add your answer

Q9. explain type of inheritance

Ans.

Type of inheritance in object-oriented programming determines how a subclass can inherit attributes and methods from a superclass.

  • Single inheritance: a subclass inherits from only one superclass.

  • Multiple inheritance: a subclass inherits from multiple superclasses.

  • Multilevel inheritance: a subclass inherits from a superclass, which in turn inherits from another superclass.

  • Hierarchical inheritance: multiple subclasses inherit from a single superclass.

  • Hybrid inheritance: a combi...read more

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter