100 Basic Python Interview Questions Part Three (41-60) Python topic month

100 Basic Python Interview Questions Part 3.(41-60) Python topic month

This article is participating in the "Python theme Month" view details about the active links

100 basic Python interview questions part one (1-20) Python topic month

100 basic Python interview questions Part 2 (21-40) Python topic month


100 basic Python interview questions part three (41-60) Python topic month

Q-1: What is Python, what are the benefits of using it, and what is your understanding of PEP 8? Q-2: What is the output of the following Python code snippet? Prove your answer. Q-3: If the program does not require actions but needs it grammatically, what statements can be used in Python? Q-4: What is the process of using "~" to get the home directory in Python? Q-5: What are the built-in types available in Python? Q-6: How to find errors or perform static analysis in Python applications? Q-7: When to use Python decorators? Q-8: What is the main difference between a list and a tuple? Q-9: How does Python handle memory management? Q-10: What is the main difference between lambda and def? Q-11: Use the python reg expression module "re" to write a reg expression to verify the email ID? Q-12: What do you think is the output of the following code snippet? Is there an error in the code? Q-13: Are there switch or case statements in Python? If not, what is the reason for the same? Q-14: What are the built-in functions that Python uses to iterate over a sequence of numbers? Q-15: What are the possible optional statements in Python's try-except block? Q-16: What is a string in Python? Q-17: What is a slice in Python? Q-18: What is %s in Python? Q-19: Are strings immutable or mutable in Python? Q-20: What is the index in Python?


















Q-21: What is a docstring in Python? Q-22: What are the functions in Python programming? Q-23: How many basic types of functions are there in Python? Q-24: How do we write functions in Python? Q-25: What is the function call or callable object in Python? Q-26: What does the return keyword in Python do? Q-27: What is "call by value" in Python? Q-28: What is "call by reference" in Python? Q-29: What is the return value of the trunc() function? Q-30: Must a Python function return a value? Q-31: What is the function of continue in Python? Q-32: What is the purpose of id() function in Python? Q-33: What is the function of *args in Python? Q-34: What does **kwargs do in Python? Q-35: Does Python have a Main() method? Q-36: What is the function of __ Name __ in Python? Q-37: What is the purpose of "end" in Python? Q-38: When should I use "break" in Python? Q-39: What is the difference between pass and continue in Python? Q-40: What is the function of len() in Python? Q-41: What is the function of chr() in Python?




















Q-42: What is the function of ord() in Python? Q-43: What is Rstrip() in Python? Q-44: What are the spaces in Python? Q-45: What is isalpha() in Python? Q-46: How do you use the split() function in Python? Q-47: What is the function of the join method in Python? Q-48: What is the function of the Title() method in Python? Q-49: What makes CPython different from Python? Q-50: Which package is the fastest form of Python? Q-51: What is the GIL in Python language? Q-52: How does Python achieve thread safety? Q-53: How does Python manage memory? Q-54: What are tuples in Python? Q-55: What is the dictionary in Python programming? Q-56: What is the set object in Python? Q-57: What is the use of dictionaries in Python? Q-58: Is a Python list a linked list? Q-59: What is the Class in Python? Q-60: What are the attributes and methods in the Python class?


















Q-41: What is the function of chr() in Python?

The chr() function was re-added in Python 3.2. In version 3.0, it was removed.

It returns a string representing the character whose Unicode code point is an integer.

For example, chr(122) returns the string'z' and chr(1212) returns the string' '.

Back to list


Q-42: What is the function of ord() in Python?

Ord(char) in Python accepts a string with a size of 1. If it is a Unicode type object, it returns an integer representing the Unicode code format of the character, or if the parameter is an 8-bit string type, it returns the value of a byte .

>>> the ord ( "Z" ) 122 Copy Code

Back to list


Q-43: What is Rstrip() in Python?

Python provides the rstrip() method, which can copy strings but omit whitespace characters from the end.

rstrip() escapes characters from the right end according to the parameter value, that is, a string that mentions the character group to be excluded.

The signature of rstrip() is:

str .rstrip([char sequence/pre> Copy code
#Example test_str = 'Programming' # trailing space are excluded Print (test_str.rstrip ()) copying the code

Back to list


Q-44: What are the spaces in Python?

Spaces represent the characters we use for spacing and separation.

They have an "empty" representation. In Python, it can be a tab character or a space.

Back to list


Q-45: What is isalpha() in Python?

Python provides this built-in isalpha() function to process strings.

If all the characters in the string are alphabetic type, it returns True, otherwise it returns False.

Back to list


Q-46: How do you use the split() function in Python?

Python's split() function processes strings, cutting a large block into smaller blocks or substrings. We can specify a delimiter to start splitting, or it uses spaces as one by default.

#Example STR = 'CSV PDF JSON' Print ( STR .split ( "" )) Print ( STR .split ()) copying the code

Output:

[ 'pdf' , 'csv' , 'json' ] [ 'pdf' , 'csv' , 'json' ] Copy the code

Back to list


Q-47: What is the function of the join method in Python?

Python provides the join() method for strings, lists, and tuples. It combines them and returns a unified value.

Back to list


Q-48: What is the function of the Title() method in Python?

Python provides the title() method to convert the first letter of each word to uppercase and the rest to lowercase.

#Example STR = 'LEARN Python' Print ( STR .title ()) copying the code

Output:

Learn PythonCopy code

Now, check out some general Python interview questions.

Back to list


Q-49: What makes CPython different from Python?

The core of CPython is developed in C. The prefix "C" represents this fact. It runs an interpreter loop to translate Python-ish code into C language.

Back to list


Q-50: Which package is the fastest form of Python?

PyPy provides maximum compatibility, while using CPython implementation to improve its performance.

Tests confirmed that PyPy is nearly five times faster than CPython. It currently supports Python 2.7.

Back to list


Q-51: What is the GIL in Python language?

Python supports GIL (Global Interpreter Lock), which is a mutual exclusion lock used to protect access to Python objects and synchronize multiple threads to run Python bytecode at the same time.

Back to list


Q-52: How does Python achieve thread safety?

Python ensures safe access to threads. It uses GIL mutexes to set up synchronization. If the thread loses the GIL lock at any time, then you must make the code thread safe.

For example, many Python operations are performed atomically, such as calling the sort() method on a list.

Back to list


Q-53: How does Python manage memory?

Python implements a heap manager internally, which stores all its objects and data structures.

This heap manager allocates/deallocates heap space for objects.

Back to list


Q-54: What are tuples in Python?

Tuple is an immutable collection type data structure in Python.

They are similar to sequences, just like lists. However, there are some differences between tuples and lists; the former does not allow modification, while lists allow.

In addition, tuples are enclosed in parentheses, but there are square brackets in the syntax of the list.

Back to list


Q-55: What is the dictionary in Python programming?

A dictionary is a data structure, called an associative array in Python, used to store a collection of objects.

The collection is a set of keys with a single associated value. We can call it hash, map or hash map because it is called in other programming languages.

Back to list


Q-56: What is the set object in Python?

A collection is an unordered collection object in Python. They store unique and immutable objects. Python's implementation is derived from mathematics.

Back to list


Q-57: What is the use of dictionaries in Python?

A dictionary has a set of objects (keys) that map to another set of objects (values). Python dictionaries represent the mapping of unique keys to values.

They are changeable and therefore will not change. The value associated with the key can be any Python type.

Back to list


Q-58: Is a Python list a linked list?

A Python list is a variable-length array, which is different from a C-style linked list.

Internally, it has a continuous array for referencing other objects, and stores pointers to array variables and their lengths in the list header structure.

Here are some Python interview questions about classes and objects.

Back to list


Q-59: What is the Class in Python?

Python supports object-oriented programming and provides almost all OOP features for program use.

Python classes are the blueprint for creating objects. It defines member variables and obtains the behaviors associated with them.

We can do this by using the keyword "class". The object is created from the constructor. This object represents an instance of the class.

In Python, we generate classes and instances in the following ways.

>>> class Human : # Create the class ... pass >>>man = Human() # Create the instance >>> print (man) <__main__.Human object at 0x0000000003559E10 > Copy code

Back to list


Q-60: What are the attributes and methods in the Python class?

If a class does not define any functions, it is useless. We can do this by adding attributes. They are used as containers for data and functions. We can add an attribute directly to the class body.

>>> class Human : ... profession = "programmer" # specify the attribute'profession' of the class >>> man = Human() >>> print (man.profession) programmer Copy code

After adding the attributes, we can continue to define the function. Usually, we call them methods. In the method signature, we must always provide a self keyword for the first parameter.

>>> class Human : profession = "programmer" def set_profession ( self, new_profession ): self.profession = new_profession >>> man = Human() >>> man.set_profession( "Manager" ) >>> print (man.profession) Manager Copy code

Back to list


Summary-100 basic Python interview questions

I have been writing a technical blog for a long time, and this is an interview question I shared. Hope you will like it! Here is a summary of all my original and work source code:

Github , Gitee

related articles:

Recommendations of excellent articles in the past:

If you really learned something new from this article, like it, bookmark it and share it with your friends. Finally, don t forget to support it or