p

python tutorial - Interview questions on python - learn python - python programming



python interview questions :11

What is the index access method called?

  • In Python, what is the [1:3] syntax on the second line called
test = (1,2,3,4,5)
print(test[1:3])
click below button to copy the code. By Python tutorial team
  • The second parameter ("3") seems to be the index - 1 (3 - 1 = 2)

python interview questions :12

Can't concat bytes to str?

  • This is proving to be a rough transition over to python on here:
f = open( 'myfile', 'a+' )
f.write('test string' + '\n')

key = "pass:hello"
plaintext = subprocess.check_output(['openssl', 'aes-128-cbc', '-d', '-in', test, '-base64', '-pass', key])
print (plaintext)

f.write (plaintext + '\n')
f.close()
The output file looks like:
test string
click below button to copy the code. By Python tutorial team

python interview questions :13

What Is The Statement That Can Be Used In Python If The Program Requires No Action But Requires It Syntactically?

  • The pass statement is a null operation. Nothing happens when it executes. You should use “pass” keyword in lowercase.
  • If you write “Pass” you’ll face an error like “NameError: name Pass is not defined.” Python statements are case sensitive
letter = "hai sethuraman"
for i in letter:
    if i == "a":
        pass
        print("pass statement is execute ..............")
    else:
        print(i)
click below button to copy the code. By Python tutorial team

python interview questions :14

What’s The Process To Get The Home Directory Using ‘~’ In Python?

  • You need to import the os module, and then just a single line would do the rest.
import os
print (os.path.expanduser('~'))
click below button to copy the code. By Python tutorial team

Output

/home/runner

python interview questions :15

What Are The Built-In Types Available In Python?

Here is the list of most commonly used built-in types that Python supports:

  • Immutable built-in types of Python
    • Numbers
    • Strings
    • Tuples
  • Mutable built-in types of Python
    • List
    • Dictionaries
    • Sets

python interview questions :16

How To Find Bugs Or Perform Static Analysis In A Python Application?

  • You can use PyChecker, which is a static analyzer. It identifies the bugs in Python project and also reveals the style and complexity related bugs.
  • Another tool is Pylint, which checks whether the Python module satisfies the coding standard

python interview questions :17

When Is The Python Decorator Used?

  • Python decorator is a relative change that you do in Python syntax to adjust the functions quickly.

python interview questions :18

What Is The Key Difference Between A List And The Tuple?

List Vs Tuple.

  • The major difference between a list and the tuple is that the list is mutable while tuple is not.
  • A tuple is allowed to be hashed, for example, using it as a key for dictionaries.

python interview questions :19

How Does Python Handle The Memory Management?

  • Python uses private heaps to maintain its memory. So the heap holds all the Python objects and the data structures. This area is only accessible to the Python interpreter; programmers can’t use it.
  • And it’s the Python memory manager that handles the Private heap. It does the required allocation of the heap for Python objects.
  • Python employs a built-in garbage collector, which salvages all the unused memory and offloads it to the heap space.

python interview questions :20

What Are The Principal Differences Between The Lambda And Def?

Def.

  • def can hold multiple expressions while lambda is a uni-expression function.
  • def generates a function and designates a name so as to call it later. lambda forms a function and returns the function itself.
  • def can have a return statement. lambda can’t have return statements

Lambda

  • lambda supports to get used inside a list and dictionary.
  • By the way, retrieving only a slice at an opening index that surpasses the no. of items in the list won’t result in an IndexError. It will just return an empty list.

Related Searches to Interview questions on python