Questions #1


Python Interview Frequently Asked Questions with Answers (No Work Experience)



Download 85,32 Kb.
bet21/24
Sana06.07.2022
Hajmi85,32 Kb.
#752107
1   ...   16   17   18   19   20   21   22   23   24
Bog'liq
interview en

Python Interview Frequently Asked Questions with Answers (No Work Experience)


AT 9. Tell us about the help() and dir() functions in python.
The help() function shows the documentation string and help for its argument:
>>> import copy
>>> help(copy.copy)
Help on function copy in module copy: # help on copy function in copy module :
copy(x)
Shallow copy operation on arbitrary Python objects. # a shallow copy operation for the selected python object.
See the module's __doc__ string for more info .
The dir() function returns a list containing the namespace in the object:
>>> dir(copy.copy)
["__annotations__", "__call__", "__class__", "__closure__", "__code__", "__defaults__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", " __ge__", "__get__", "__getattribute__", "__globals__", "__gt__", "__hash__", "__init__", "__init_subclass__", "__kwdefaults__", "__le__", "__lt__", "__module__", "__name__" , "__ne__", "__new__", "__qualname__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__"]
AT 10 O'CLOCK. How to get a list of all dictionary keys?
These questions should be answered in detail, with examples. This task is performed using the keys() function:
>>> mydict={"a":1,"b":2,"c":3,"e":5}
>>> mydict.keys()
dict_keys(["a", "b", "c", "e"])
AT 11. What is a cut?
Slicing is a technique that allows you to get part of a list, tuple, or string.
>>> (1, 2, 3, 4, 5)[2:4]
(3, 4)
>>> [7, 6, 8, 5, 9][2:]
[8, 5, 9]
>>>"Hello"[:-1]
"Hell"
AT 12. How are comments written in python?
The symbol # is used for this. Anything written on the line after it is considered a comment and is ignored. Comments are used to explain the purpose of the written code. There are no multi-line comments in the literal sense of the word in python.
>>> # first comment line
>>> # second comment line
B13. How to check that all characters of a string are alphanumeric?
The isalnum() method is used for this.
B14. How to convert the first character of a string to uppercase?
There is a capitalize() method for this:
>>> "ayushi".capitalize()
"Ayushi"
B15. Everyone knows that python is in fashion today. But true acceptance of a new technology involves understanding its shortcomings. What can you say about this?
What are the limitations in Python?
- the interpreted nature of python reduces the speed of program execution
- it is not profitable to use for mobile devices and browsers
- being a language with dynamic data typing, it uses duck typing; in connection with this, runtime errors appear;
- Possibilities of access to databases are poorly developed in it; therefore, python is not ideal for applications with very large databases;
- low entry requirements, that is, everyone can try their hand at python; this sometimes reduces the quality of the code;
- Python has an individual style.
B16. How to find out in python what directory we are currently in?
The getcwd() function is used for this. It is imported from the os module:
>>> import os
>>> os.getcwd()
"C:\\Users\\lifei\\AppData\\Local\\Programs\\Python\\Python36-32"
B17. How to insert an object so that it is at a certain index?
Let's create a list first:
>>> a=[1, 2, 4]
Then we use the insert() method. In it, the first argument will be the index under which the object is inserted, and the second is the value of the object:
>>> a.insert(2,3)
>>> a
[1, 2, 3, 4]
B18. How can you reverse the order of elements in a list?
There is a reverse() method for this:
>>> a.reverse()
>>> a
[4, 3, 2, 1]
B19. What is an interpreter prompt?
When we enter the python interpreter, we see the following line:
>>>
IN 20. What needs to be done for the function to return a value?
The return keyword is used for this:
>>> def add(a, b):
return a + b
AT 21. What is a block?
When we write a statement (statement), we need to end the first line with a colon, and below it write a block of code that is executed within this statement. Each line of the block is written with the same indentation.
>>> if 3 > 1:
print("Hello")
print("goodbye")
hello
Goodbye
B 22. Why need break and continue?
They are used to control the sequence of operations: break stops the execution of the loop and transfers execution to the next block of code, continue, as it were, jumps to the next iteration of the loop and does not stop its execution.
B23. If we don't put a colon at the end of the line for the "do-while" loop, will it still work?
Python doesn't implement such a loop. This is one of those tricky questions when it mentions elements of other languages.
B24. Write in one line how you can get the latest value letter in the string.
The value of a letter is determined by its ASCII code. The max() function is suitable for this:
>>> max("flyNg")
"y"
The following line of code can be explained using the same logic:
>>> max("fly{}iNg")
"}"
B25. In what areas does python excel?
Python is best used in the following areas:
- web applications
- Graphical user interfaces for desktop PCs
- scientific and arithmetic applications
- software development
- development of training programs
- applications for business
- network applications
- games, 3D graphics
B26. Can you name ten built-in Python functions?
The complex() function creates a complex number:
>>> complex(3.5,4)
(3.5+4j)
The eval() function executes the line:
>>> eval("print(max(22,22.0) - min(2,3))")
twenty
The filter() function filters out elements for which the specified condition is true.
>>> list(filter(lambda x: x%2 == 0,[1, 2, 0, False]))
[2, 0, False]
The format() function helps to set the format of a string:
>>> print("a = {0} but b = {1}".format(a, b))
a = 2 but b = 3
The hash() function returns the hash value of an object:
>>> hash(3.7)
644245917
The hex() function converts a number to a hexadecimal number:
>>> hex(14)
"0xe"
The input() function reads the input and returns a string:
>>> input("Enter a number")
Enter a number7
"7"
The len() function returns a number indicating the length of the string:
>>> len("Ayushi")
6
The locals() function returns a dictionary with the local table of names:
>>> locals()
{"__name__": "__main__", "__doc__": None, "__package__": None, "__loader__": , "__spec__": None, "__annotations__": {}, "__builtins__" : , "a": 2, "b": 3}
The open() function opens file :
>>> file = open("tabs.txt")
B27. What is the output of the following code:
>>>word="abcdefghij"
>>> word[:3] + word[3:]
Output : "abcdefghij".
B28. How to convert list to string?
The join() method is suitable for this:
>>> nums=["one","two","three","four","five","six","seven"]
>>> s=" ".join(nums)
>>>s
"one two three four five six seven"
B29. How to remove a duplicate element from a list?
To do this, you can convert the list into a set (set):
>>> list = [1, 2, 1, 3, 4, 2]
>>>set(list)
{1, 2, 3, 4}
B30. Can you explain the life cycle of a thread?
In general, the cycle looks like this:
- first, a class is created that replaces the class execution method in the thread, and we create an instance for this class;
- call start(), which prepares the thread for execution;
- transfer the thread to the state of execution;
- you can call different methods, such as sleep() and join(), which put the thread into standby mode;
- when the idle or execution mode is terminated, other pending threads are prepared for execution;
- after completion of the execution, the thread stops.


Download 85,32 Kb.

Do'stlaringiz bilan baham:
1   ...   16   17   18   19   20   21   22   23   24




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish