1. What are the Key Features of Python?
· Easy to Code: Python is a high-level programming language. Python is
very easy to learn as compared to other languages like C, C#, Javascript,
Java, etc. It is
also a developer-friendly language.
· Free and Open Source: Python language is freely available at the
official website and you can download it from the website.
· Object-Oriented Language: One of the key features of python is
Object-Oriented programming. Python supports object-oriented
language and concepts of classes, objects encapsulation, etc.
· Python is 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.
· Python is an Integrated language: Python is also an Integrated language
because we can easily integrate python with other languages like c, c++, etc.
2. What type of language is python? Programming or Scripting?
Python is capable of scripting, but in the general sense, it is considered
as a general-purpose programming language.
3. What are Common built-in data types in Python?
The common built-in data types in python are-
Numbers, List, Tuple, String, Set, Dictionary, Boolean.
4. What are python modules? Name some commonly used built-in modules in python?
Python modules are files containing Python code. This code can either be functions,
classes, or variables. A Python module
is a .py file containing executable code.
Some of the commonly
used built-in modules are:
·
os
·
sys
·
math
·
random
·
data time
· JSON
5. Is Python Case Sensitive?
Yes. Python is a case-sensitive language.
6. What is List and Tuple in python?
List: An ordered sequence of items is called a list. The elements of a list
may belong to different data types. lists are mutable, which means we
can change the value of a list. Eg. - [5, 'market', 2.4]
Tuple: It is also an ordered sequence of elements. but tuples are
immutable, which means we can't be changed. E.g - (3,'tool',1).
7. What is Set and
Dictionary in python?
Set - Sets are collections of unique items that are not in order.
E.g - { 7,6,8 }.
Dictionary - A dictionary stores values in key and value pairs where
each value can be accessed through its key.
The order is not important in it. E.g - {1: ' apple ', 2: ' Cherry '}
8. What is Slicing in Python?
The slice() function returns a slice object.
A slice object is used to specify how to slice a sequence.
We can specify where to start and where to
end the slicing.
E.g - ( " Elon ", "Jeff " , " Warrent " , "
Mark " , " Sunder " ,
" Parag ",
" Satya ")
x = slice(2,5)
print(x)
output - (" Warrent " , " Mark " , " Sunder " )
9. What is the difference
between the .py and .pyc files?
The .py files are the python source code files.
While the .pyc files contain the bytecode of the python files.
.pyc files are created when the code is imported from
some other source.
10. What are Keywords
in python?
Keywords are reserved words that have special meanings.
we are generally used to define types of variables.
Keywords can't be used as variable or function names.
Keywords in python:-
And, Or, Not, If, Elif, Else, Def, Lamda, Pass, Try, With, Assert, etc.
11. What is namespace
in Python?
A namespace is a naming system used to make sure that names a
unique to avoid naming conflicts.
12. What are Global variables and Local variables in python?
Global Variables: Variables declared outside a function are called global variables.
These variables can be accessed by any
function in the program.
Local Variables: Variables declared inside a function is called local variable.
This variable is present in the local space.
13. What is Type Conversion in python?
Type conversion refers
to the converstion of one data type into another.
int(), float(), ord(), hex(), oct(), tuple(), set(), list(), dict(), str(), complex(real, imag).
14. What is the difference between Python Arrays and Lists?
Array and lists, in python, have the same way of storing data.
But arrays can hold only a single data type element whereas lists
can hold any data type elements.
E.g - array(1,2,3,4) and list( 1, ' abd ' , 4.6).
15. What is lambda function ?
An anonymous function is known as a lambda function.
This function can have any number of parameters but, can have just one statement.
16. What does [::-1] do?
[::-1] is used to
reverse the order of an array or a sequence.
E.g :
import array as arr
Array =
arr.array('i',[1,2,3,4,5])
Array[::-1]
O/P - array('i', [5,4,3,2,1])
17. What are python
iterators?
Iterators are objects which can be traversed through or iterated upon.
18. How do you write
comments in python?
For single-line comments, we use a # character.
E.g - #This is a single-line comment.
For multiple line
comments, we use (' ' ') in the first line and last line.
E.g - ' ' ' This is
multiple line
comment ' ' ' .
19. What are docstrings in python?
Docstrings are not actually comments, but they are documentation strings.
These docstrings are within triple quotes. They are not assigned to any
variable and therefore, at times, serve the purpose of comments as well.
20. What is the purpose of ' is ', ' not ', and ' in ' operators?
Operators are special
functions.
is: returns true when
2 operands are true.
not: returns the
inverse of the boolean value.
in: checks if some element is present in some sequence.
21. What does len() do?
It is used to determine the length of a string, a list, an array, etc.
22. What are Python
packages?
Python packages are namespaces containing multiple modules.
23. How can the file be deleted in python?
To delete a file in python, we need to import the OS Module.
After that, we need to use the os. remove() function.
24. How to add values to python array ?
Elements can be added to an array using the append(), extend()
and the insert(i,x) functions.
25. How to remove
values to a python array ?
Array element can be removed using pop() or remove() method.
0 Comments