1) What is python?
Ans: Python is high level, general purpose, and very popular programming language. It is
being used in web development, machine learning applications etc. Python program is
generally smaller than the other programming language.
2) Which are special operators in python?
Ans: Python includes several special operators that serve unique purpose beyond standard
arithmetic or logical operation. Here are the main types of special operators:
1) Identity Operators: These operators are used to compare the memory locations
of two objects. The identity operators are:
i) is :- it returns True if both operands refer to the same object in memory.
ii) is not :- it return True if both operands do not refer to the same object.
2) Membership Operators: These operators are used to test for membership within
a sequence (like lists, tuples or string). The two membership operators are:
i) in :- It return true if the value is found in the sequence.
ii) not in :- It returns True if the value is not found in the sequence.
3) Explain any five built in List functions.
Ans:
Python comes with a rich set of built-in functions that are readily available for use
without the need for importing any modules. These functions perform a variety of tasks,
from mathematical operations to data type conversions and more. Here are some key
built-in functions in Python:
1. len() The len() function returns the number of items in an object, such as a list, string,
or tuple.
my_list = [1, 2, 3, 4]
length = len(my_list) # Returns 4
2. max() and min() These functions return the largest and smallest items in an iterable,
respectively. They can also be used with multiple arguments.
numbers = [10, 20, 30]
largest = max(numbers) # Returns 30
smallest = min(numbers) # Returns 10
3. sum() The sum() function returns the sum of all items in an iterable, such as a list or
tuple.
numbers = [1, 2, 3, 4]
total = sum(numbers) # Returns 10
4. sorted() The sorted() function returns a new sorted list from the items in an iterable. It
does not modify the original iterable.
my_list = [3, 1, 4, 2]
sorted_list = sorted(my_list) # Returns [1, 2, 3, 4]
1) Write in brief about anonymous function.
Ans:
• Python Lambda Functions are anonymous functions means that the function is
without a name.
• As we already know the def keyword is used to define a normal function in
Python. Similarly, the lambda keyword is used to define an anonymous function
in python
Python Lambda Function Syntax
Syntax: lambda arguments: expression
• This function can have any number of arguments but only one expression,
which is evaluated and returned.
• One is free to use lambda functions wherever function objects are
required.
• You need to keep in your knowledge that lambda functions are
syntactically restricted to a single expression.
• It has various uses in particular fields of programming, besides other types
of expressions in functions.
2) What are features of python?
Ans: Features of Python is as follows:
1) Free and open source:
Python languages is freely available at the official website and you can download it.
Since it is open source, this means that source code is also available to the [Link]
you can download it, use it as well as share it.
2) Easy to code:
Python is a high-level programming language. Python is very easy to learn the
language as compared to other languages like C, C#, JavaScript, Java, etc. It is very
easy to code in the python language and anybody can learn python basics in few hours
or days.
3) Easy to read:
As you will see, learning Python is quite simple. As was already established, Python’s
syntax is really straightforward. The code block is defined by the indentation rather
than by semicolons or brackets.
4) Object Oriented language:
One of the key features of Python is object-oriented programming. Python supports
object-oriented language and concepts of classes, object, inheritance, encapsulation
etc.
5) GUI Programming Support:
Graphical User Interfaces can be made using a module such as PyQt5, wxPythpn, or
TKinter in Python.PyQt5 is the most popular option for creating graphical apps with
Python.
6) High-Level Language:
Python is a high-level language. When we write programs in python, we do not need
to remember the system architecture, nor do we need to manage the memory.
7) Large Community Support:
Python has gained popularity over the years. Our questions are constantly answered
by the enormous Stack Overflow community. These websites have already provided
answers to many questions about Python, so Python users can consult them as needed.
8) Easy to Debug:
Excellent information for mistake tracing. You will be able to quickly identify and
correct the majority of your program’s issues once you understand how to interpret
Python’s error trace. Simply by glancing at the code you can determine what it is
designed to perform.
9) Python is a Portable language:
Python language is also a portable language. For example, if we have Python code for
windows and if we want to run this code on other platforms such as Linux, Unix, and
Mac then we do not need to change it, we can run this code on any platform.
10) Python is an integrated language:
Python is an integrated language because we can easily integrate Python with other
languages like C, C++, etc.
11) Interpreted language:
Python is an Integrated Language because Python code is executed line by line at a
time like other languages C, C++, Java, etc. there is no need to compile Python code
this makes it easier to debug our code. The source code of Python is converted into an
immediate form called bytecode.
12) Large Standard Library:
Python has large library that provides a rich set of modules and functions so you do
not have to write your own code for every single thing. There are many libraries
present in Python such as regular expressions, unit testing, web browsers etc.
13) Dynamically typed language:
Python is a dynamically typed language that means the type (e.g: int, double, long etc)
for a variable is decided at run time not in advance because of this feature we don’t
need to specify the type of variable.
14) Scalable:
Python provides a better structure and support for large Programs than shell scripting.
It can be used as a scripting language or can be compiled to byte code for building
large application.
15) Extendable:
You can add low-level modules to the Python interpreter. These modules enable
Programmers to add to or customize their tools to be more efficient. It can be easily
integrated with C, java.
6) Write a python program to create a current date and time?
from datetime import datetime
now = [Link]()
print("Current date and time:", [Link]("%d-%m-%y %H:%M:%S"))
1) What is the use of import statement?
Ans: The import statement in python is a fundamental feature that allows you to access
code from one module in another module. The capability is essential for organizing and
reusing code efficiently. Here are the key uses and functionalities of the import statement:
1. Accessing code from other modules.
2. Namespace Management.
3. Single loading of modules.
4. Importing specific attributes.
5. Using Aliases
6. Dynamic importing
7. Organizing code.
2) What is the use of math module?
Ans: The math module in python is a built-in library that provides a wide range of
mathematical functions and constants. It is designed to simplify mathematical tests and
enhance the capabilities of python for performing complex operation. Following are the
key uses of the math module:
1. Mathematical function
2. Constants
3. Advance mathematical operations
4. Trigonometric functions
5. Performance