You are on page 1of 6

Q.1 What is Python? How is it different from other programming languages?

Python is a high-level, interpreted programming language, it is simple and readable.


It was created by Guido van Rossum and first released in 1991.

Here's how Python differs from other programming languages:


Readability: Python's syntax is designed to be clear and concise, making it easier to read and understand code.

Interpreted: Python is an interpreted language, it does not need to be compiled before execution.

Dynamic Typing: Python is dynamically typed, which means that variable types are automatically inferred at runtime. Unlike statically
typed languages like C++ or Java, you don't need to declare the type of a variable explicitly.

Versatility: Python is a versatile language used for a wide range of applications, including web development, data analysis, artificial
intelligence,scientific computing, automation, and more

Object-Oriented: Python supports object-oriented programming (OOP) paradigms, allowing developers to create and objects, encapsulate
data, and implement inheritance, polymorphism, and encapsulation.

Community: Python has a large and active community of developers who contribute to its growth and support through various forums,
mailing lists, and online communities.

Cross-platform: Python is cross-platform, meaning that code written in Python can run on various operating systems without modification.
Q.2 Explain the differences between Python 2 and Python 3.

Keys Python 2 Python 3


Integer Division Integer division (e.g., 5/2) returns the Integer division always returns a
floor value of the division if both floating-point number, regardless of
operands are integers. the operands.

Unicode Support: Strings are represented as ASCII by Strings are Unicode by default.
default. Unicode strings are Unicode strings are the default, and
represented with a u prefix. the u prefix is no longer used.
Range vs. xrange: The range() function returns a list. The range() function returns a
generator-like object similar to the
xrange() function in Python 2.
Input Function: The input() function evaluates the The input() function returns the
user's input as Python code. user's input as a string. To evaluate
Python code, you can use the
eval(input()) function.
Keys Python 2 Python 3
Exceptions raise statement can be used with or raise statement requires parentheses.
without parentheses.
Iterating Through Dictionaries: dict.keys(), dict.values(), and dict.keys(), dict.values(), and
dict.items() return lists. dict.items() return dictionary views,
which are dynamic and reflect
changes to the dictionary.
Unicode Support in str and bytes str represents bytes, and unicode str represents Unicode strings, and
Types: represents Unicode strings. bytes represents bytes. Use encode()
and decode() methods to convert
between the two.
Division Operator / performs integer division if both / always performs true division,
operands are integers. returning a floating-point number.
Ordered Dictionary: collections.OrderedDict is not part of collections.OrderedDict is part of the
the standard library. standard library and maintains the
order of insertion.
Q3. What are the advantages of using Python?

• Python offers several advantages that make it a popular choice for developers across
various domains:
• Readability
• Simplicity and Ease of Learning
• Versatility
• Community and Support
• Portability
• Interpreted Language
• Large Standard Library
• Strong Ecosystem of Third-party Packages.
• Object-Oriented Programming Support
• High-level Language
Q.4 What is PEP 8? Why is it important?

• PEP 8 stands for Python Enhancement Proposal 8. It is a style guide for writing Python code, written by
Guido van Rossum, Barry Warsaw, and Nick Coghlan. PEP 8 provides guidelines and best practices for
formatting Python code to enhance its readability and maintainability. Here's why PEP 8 is important:
• Consistency: PEP 8 promotes consistency in code style across different projects
• Readability: PEP 8 emphasizes readability by encouraging clear and concise code formatting
• Reduced Errors: Adhering to PEP 8 guidelines can help reduce the likelihood of introducing errors in code.
• Enforced by Tools: There are various tools and linters available that can automatically check code against PEP
8 guidelines and flag any violations.
• Better Code Reviews: PEP 8 provides a common set of standards for code formatting, which makes code
reviews more efficient and effective.
• Maintainability: Well-formatted code following PEP 8 guidelines is easier to maintain over time
• Professionalism: Adhering to PEP 8 demonstrates professionalism and respect for the Python community's
conventions and best practices.
Q5. Explain the difference between a list and a tuple in Python .
In Python, both lists and tuples are used to store collections of items, but they have several differences:
1.Mutability:
•Lists are mutable, meaning that you can modify their elements after creation. You can add, remove, or change
items in a list.
•Tuples are immutable, meaning that once they are created, their elements cannot be changed. You cannot add,
remove, or change items in a tuple.
2.Syntax:
•Lists are defined using square brackets [ ].
•Tuples are defined using parentheses ( ).
3.Performance:
•Due to their immutability, tuples are generally faster than lists, especially for operations like iteration and
accessing elements.
•Lists are slower than tuples, especially for large collections or when frequently modifying elements, due to
the overhead of managing memory
and dynamic resizing.
4.Use Cases:
•Lists are typically used when you need a collection of items that can be modified, such as storing user inputs,
maintaining dynamic data,
or representing sequences of elements.
•Tuples are often used when you want to store a fixed collection of items that should not be changed, such as
coordinates, constant values,
or returning multiple values from a function.

You might also like