This article is participating in Python Theme Month. See the link to the event for more details

100 Basic Python Interview Questions Part 1 (1-20) | Python topic month

100 Basic Python Interview Questions Part 2 (21-40) | Python topic month


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

Q-1: What is Python, what are the benefits of using it, and what do you understand about PEP 8? Q-2: What is the output of the following Python snippet? Prove your answer. Q-3: What statements can be used in Python if the program does not need an action but syntactically requires it? 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 do I find errors or perform static analysis in a Python application? Q-7: When to use Python decorators? Q-8: What are the main differences between lists and tuples? Q-9: How does Python handle memory management? Q-10: What are the main differences between lambda and DEF? Q-11: Write a reg expression using the Python reg expression module “re” to verify the email ID? Q-12: What do you think the output of the following code snippet is? Are there any errors in the code? Q-13: Are there switch or case statements in Python? If not, what is the same reason? Q-14: What is Python’s built-in function for iterating over sequences 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 are indexes in Python? Q-21: What is a docstring in Python? Q-22: What are 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 are function calls or callable objects 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 trunc()? Q-30: Must Python functions return a value? Q-31: What does a continue do in Python? Q-32: What is the purpose of the id() function in Python? Q-33: * What is the role of args in Python? Q-34: What does **kwargs do in Python? Q-35: Does Python have a Main() method? Q-36: what does __ Name __ do in Python? Q-37: What is the purpose of “end” in Python? Q-38: When should you use “break” in Python? Q-39: What’s the difference between pass and continue in Python? What does the q-40: len() function do in Python? Q-41: What does the CHR () function do in Python? Q-42: What does the ord() function do in Python? Q-43: What is Rstrip() in Python? Q-44: What is a space in Python? Q-45: What is isalpha() in Python? Q-46: How do you use the split() function in Python? Q-47: What does the Join method in Python do? Q-48: What does the Title() method do 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? Q-52: How can Python be thread safe? Q-53: How does Python manage memory? Q-54: What is a tuple in Python? Q-55: What are dictionaries in Python programming? Q-56: What is a set in Python? Q-57: What is the use of dictionaries in Python? Q-58: Are Python lists linked? Q-59: What is a Class in Python? Q-60: What are attributes and methods in Python classes?


Q-41: What does the CHR () function do in Python?

The CHR () function was readded 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’ while CHR (1212) returns the string ‘Ҽ’.

Return to the directory


Q-42: What does the ord() function do in Python?

Ord (char) in Python takes a string of size 1 and returns an integer representing the character in Unicode code format if it is an object of Unicode type, or the value in bytes if the argument is an 8-bit string type.

>>> ord("z")
122
Copy the code

Return to the directory


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

Python provides the rstrip() method, which copies a string but omits whitespace from the end.

Rstrip () escapes characters from the right, that is, a string, according to the parameter value, referring to the group of characters to exclude.

The signature of rstrip() is:

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

Return to the directory


Q-44: What is a space in Python?

Spaces represent the characters we use for spacing and separation.

They have an “empty” representation. In Python, it can be a TAB or a space.

Return to the directory


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

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

Return True if all characters in the string are of alphabetic type, False otherwise.

Return to the directory


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

Python’s split() function handles strings, cutting a large chunk into smaller chunks or substrings. We can specify a delimiter to start splitting, or it defaults to a space as one.

#Example
str = 'pdf csv json'
print(str.split(""))
print(str.split())
Copy the code

Output:

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

Return to the directory


Q-47: What does the Join method in Python do?

Python provides join() methods for strings, lists, and tuples. It combines them and returns a uniform value.

Return to the directory


Q-48: What does the Title() method do 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())
Copy the code

Output:

Learn Python
Copy the code

Now, take a look at some common Python interview questions.

Return to the directory


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.

Return to the directory


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

PyPy provides maximum compatibility while leveraging the CPython implementation to improve its performance.

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

Return to the directory


Q-51: What is the GIL in Python?

Python supports the GIL (Global interpreter lock), which is a mutex that protects access to Python objects and synchronizes multiple threads running Python bytecode simultaneously.

Return to the directory


Q-52: How can Python be thread safe?

Python ensures secure access to threads. It uses the GIL mutex to set synchronization. If a thread loses the GIL lock at any time, then you must make your code thread-safe.

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

Return to the directory


Q-53: How does Python manage memory?

Python internally implements a heap manager that holds all of its objects and data structures.

The heap manager allocates/unallocates heap space for objects.

Return to the directory


Q-54: What is a tuple in Python?

A tuple is an immutable collection type data structure in Python.

They’re like sequences, just like lists. However, there are some differences between tuples and lists; The former does not allow modification, while the list does.

In addition, tuples are enclosed in parentheses, but lists have square brackets in their syntax.

Return to the directory


Q-55: What are dictionaries in Python programming?

A dictionary is a data structure, called an associative array in Python, that stores a collection of objects.

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

Return to the directory


Q-56: What is a set in Python?

A collection is an unordered collection object in Python. They store unique and immutable objects. Python’s implementation comes from math.

Return to the directory


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

A dictionary has one set of objects (keys) mapped to another set of objects (values). Python dictionaries represent unique key-to-value mappings.

They are mutable, so they don’t change. The value associated with the key can be of any Python type.

Return to the directory


Q-58: Are Python lists linked?

Python lists are variously long arrays, unlike C-style linked lists.

Internally, it has a contiguous array of references to 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.

Return to the directory


Q-59: What is a Class in Python?

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

Python classes are blueprints for creating objects. It defines member variables and gets the behavior associated with them.

We can do this by using the keyword “class”. Objects are created from constructors. This object represents an instance of the class.

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

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

Return to the directory


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

If a class does not define any functionality, it is useless. We can do this by adding properties. They serve 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 the code

With the properties added, we can move on to defining the function. In general, we call them methods. In method signatures, we always have to provide a self keyword for the first argument.

>>> 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 the code

Return to the directory


Summary – 100 basic Python interview questions

I’ve been writing a tech blog for a long time, and this is one of my interview questions to share. Hope you like it! Here is a summary of all my original and work source code:

Making, Gitee

Related articles:

  • 100 Basic Python Interview Questions Part 1 (1-20) | Python topic month
  • 100 Basic Python Interview Questions Part 2 (21-40) | Python topic month
  • 30 Python tutorials and tips | Python theme month

Recommended articles of the past:

  • Teach you to use Java to make a gobang game
  • Interesting way to talk about the history of JavaScript ⌛
  • The output of a Java program | Java exercises 】 【 7 sets (including parsing)
  • ❤️5 VS Code extensions that make refactoring easy ❤️
  • 140000 | 400 multichannel JavaScript 🎓 interview questions with answers 🌠 items (the fifth part 371-424)

If you do learn something new from this post, like it, bookmark it and share it with your friends. 🤗 Finally, don’t forget ❤ or 📑 for support