{"id":2703,"date":"2023-12-16T11:45:12","date_gmt":"2023-12-16T11:45:12","guid":{"rendered":"https:\/\/www.kaashivinfotech.com\/blog\/?p=2703"},"modified":"2025-08-02T10:29:18","modified_gmt":"2025-08-02T10:29:18","slug":"basic-python-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.kaashivinfotech.com\/blog\/basic-python-interview-questions-and-answers\/","title":{"rendered":"Basic Python Interview Questions and Answers"},"content":{"rendered":"<p data-start=\"245\" data-end=\"548\"><strong data-start=\"245\" data-end=\"281\">Python basic interview questions<\/strong> are a great way to assess your understanding of Python\u2019s core concepts. Python is a general-purpose, dynamic, high-level, and interpreted programming language that is widely used across various domains\u2014from web development and data science to automation and testing.<\/p>\n<p data-start=\"550\" data-end=\"834\">Python supports the <strong data-start=\"570\" data-end=\"601\">Object-Oriented Programming<\/strong> (OOP) approach, making it easier to structure and develop scalable applications. With its clear syntax and readability, Python is simple and easy to learn\u2014even for beginners\u2014while still being powerful enough for advanced developers.<\/p>\n<h3 data-start=\"1939\" data-end=\"2003\"><strong data-start=\"1946\" data-end=\"2003\">Why Interviewers Ask Python Basic Interview Questions<\/strong><\/h3>\n<p data-start=\"2005\" data-end=\"2032\">These questions help gauge:<\/p>\n<ul data-start=\"2033\" data-end=\"2298\">\n<li data-start=\"2033\" data-end=\"2092\">\n<p data-start=\"2035\" data-end=\"2092\">Your ability to understand and write basic Python scripts<\/p>\n<\/li>\n<li data-start=\"2093\" data-end=\"2130\">\n<p data-start=\"2095\" data-end=\"2130\">Problem-solving skills using Python<\/p>\n<\/li>\n<li data-start=\"2131\" data-end=\"2202\">\n<p data-start=\"2133\" data-end=\"2202\">Your grasp of programming fundamentals (loops, functions, conditions)<\/p>\n<\/li>\n<li data-start=\"2203\" data-end=\"2298\">\n<p data-start=\"2205\" data-end=\"2298\">Real-time application of Python logic in QA automation, data manipulation, or web development<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"2300\" data-end=\"2366\">For QA roles, <strong data-start=\"2314\" data-end=\"2351\">python interview questions for QA<\/strong> often include:<\/p>\n<ul data-start=\"2367\" data-end=\"2500\">\n<li data-start=\"2367\" data-end=\"2402\">\n<p data-start=\"2369\" data-end=\"2402\">Writing scripts to automate tasks<\/p>\n<\/li>\n<li data-start=\"2403\" data-end=\"2458\">\n<p data-start=\"2405\" data-end=\"2458\">Understanding Python\u2019s integration with testing tools<\/p>\n<\/li>\n<li data-start=\"2459\" data-end=\"2500\">\n<p data-start=\"2461\" data-end=\"2500\">Using assertions and exception handling<\/p>\n<\/li>\n<\/ul>\n<h2 style=\"margin-bottom: 5px; padding-top: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; white-space-collapse: collapse;\">Top Python Basic Interview Questions and Answers<\/h2>\n<figure id=\"attachment_9729\" aria-describedby=\"caption-attachment-9729\" style=\"width: 654px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\" wp-image-9729\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers.png\" alt=\"python basic interview questions\" width=\"654\" height=\"436\" srcset=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers.png 1536w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-300x200.png 300w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-1024x683.png 1024w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-768x512.png 768w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-332x221.png 332w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-664x443.png 664w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-688x459.png 688w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-1044x696.png 1044w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Python-basic-interview-questions-and-answers-1400x933.png 1400w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/><figcaption id=\"caption-attachment-9729\" class=\"wp-caption-text\">Python basic interview questions and answers<\/figcaption><\/figure>\n<p><a tabindex=\"0\">1. What is the difference between list and tuples in Python ?<\/a><\/p>\n<table width=\"100%\">\n<tbody>\n<tr>\n<td colspan=\"2\"><strong>LIST vs TUPLES<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>LIST<\/strong><\/td>\n<td><strong>TUPLES<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"219\">Lists are mutable i.e they can be edited.<\/td>\n<td width=\"291\">Tuples are\u00a0immutable (tuples are lists which can\u2019t be edited).<\/td>\n<\/tr>\n<tr>\n<td width=\"219\">Lists are slower than tuples.<\/td>\n<td width=\"291\">Tuples are faster than list.<\/td>\n<\/tr>\n<tr>\n<td width=\"219\">Syntax: list_1 = [10, \u2018Chelsea\u2019, 20]<\/td>\n<td width=\"291\">Syntax: tup_1 = (10, \u2018Chelsea\u2019 , 20)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a tabindex=\"0\">2. What are the key features of Python ?<\/a><\/p>\n<ul>\n<li>Python is an\u00a0<strong>interpreted<\/strong>\u00a0language. That means that, unlike languages like\u00a0<em>C<\/em>\u00a0and its variants, Python does not need to be compiled before it is run. Other interpreted languages include\u00a0<em>PHP<\/em>\u00a0and\u00a0<em>Ruby<\/em>.<\/li>\n<li>Python is\u00a0<strong>dynamically typed<\/strong>, this means that you don\u2019t need to state the types of variables when you declare them or anything like that. You can do things like\u00a0x=111\u00a0and then\u00a0x=\u201dI\u2019m a string\u201d\u00a0without error<\/li>\n<li>Python is well suited to\u00a0<a href=\"https:\/\/www.edureka.co\/blog\/python-class\/\" target=\"_blank\" rel=\"noopener\"><strong>object orientated programming<\/strong><\/a>\u00a0in that it allows the definition of classes along with composition and inheritance. Python does not have access specifiers (like C++\u2019s\u00a0public,\u00a0private).<\/li>\n<li>In Python,\u00a0<strong>functions<\/strong>\u00a0are<strong>\u00a0first-class objects<\/strong>. This means that they can be assigned to variables, returned from other functions and passed into functions. Classes are also first class objects<\/li>\n<li><strong>Writing Python code is quick<\/strong>\u00a0but running it is often slower than compiled languages. Fortunately\uff0cPython allows the inclusion of C-based extensions so bottlenecks can be optimized away and often are. The\u00a0<a href=\"https:\/\/www.edureka.co\/blog\/python-numpy-tutorial\/\" target=\"_blank\" rel=\"noopener\">numpy<\/a>\u00a0package is a good example of this, it\u2019s really quite quick because a lot of the number-crunching it does isn\u2019t actually done by Python<\/li>\n<li>Python finds\u00a0<strong>use in many spheres<\/strong>\u00a0\u2013 web applications, automation, scientific modeling, big data applications and many more. It\u2019s also often used as \u201cglue\u201d code to get other languages and components to play nice.\u00a0Learn more about Big Data and its applications from the\u00a0<a href=\"https:\/\/www.edureka.co\/microsoft-azure-data-engineering-certification-course\" target=\"_blank\" rel=\"noopener\">Azure Data Engineering Training Course<\/a>.<\/li>\n<\/ul>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">3. What type of language is python ? Programming or scripting ?<\/a><\/p>\n<p>Python is capable of scripting, but in general sense, it is considered as a general-purpose programming language.\u00a0To know more about Scripting, you can refer to the\u00a0<a href=\"https:\/\/youtu.be\/9F6zAuYtuFw\" target=\"_blank\" rel=\"noopener\">Python Scripting Tutorial<\/a>.<\/p>\n<p><a tabindex=\"0\">4. Python an interpreted language. Explain ?<\/a><\/p>\n<p>An interpreted language is any programming language which is not in machine-level code before runtime.\u00a0Therefore, Python is an interpreted language.<\/p>\n<p><a tabindex=\"0\">5. What is pep 8 ?<\/a><\/p>\n<p>PEP stands for\u00a0<strong>Python Enhancement Proposal.\u00a0<\/strong>It is a set of rules that specify how to format Python code for maximum readability.<\/p>\n<p><a tabindex=\"0\">6. What are the benefits of using Python ?<\/a><\/p>\n<p>The benefits of using python are-<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>Easy to use<\/strong>\u2013 Python is a high-level programming language that is easy to use, read, write and learn.<\/li>\n<li><strong>Interpreted language<\/strong>\u2013 Since python is interpreted language, it executes the code line by line and stops if an error occurs in any line.<\/li>\n<li><strong>Dynamically typed<\/strong>\u2013 the developer does not assign data types to variables at the time of coding. It automatically gets assigned during execution.<\/li>\n<li><strong>Free and open-source<\/strong>\u2013 Python is free to use and distribute. It is open source.<\/li>\n<li><strong>Extensive support for libraries<\/strong>\u2013 Python has vast libraries that contain almost any function needed. It also further provides the facility to import other packages using Python Package Manager(pip).<\/li>\n<li><strong>Portable<\/strong>\u2013 Python programs can run on any platform without requiring any change.<\/li>\n<li>The data structures used in python are user friendly.<\/li>\n<li>It provides more functionality with less coding.<strong>\u00a0<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><a tabindex=\"0\">7. What are Python namespaces ?<\/a><\/p>\n<p>A namespace in python refers to the name which is assigned to each object in python. The objects are variables and functions. As each object is created, its name along with space(the address of the outer function in which the object is), gets created. The namespaces are maintained in python like a dictionary where the key is the namespace and value is the address of the object. There 4 types of namespace in python-<\/p>\n<ol>\n<li><strong>Built-in namespace<\/strong>\u2013 These namespaces contain all the built-in objects in python and are available whenever python is running.<\/li>\n<li><strong>Global namespace<\/strong>\u2013 These are namespaces for all the objects created at the level of the main program.<\/li>\n<li><strong>Enclosing namespaces<\/strong>\u2013 These namespaces are at the higher level or outer function.<\/li>\n<li><strong>Local namespaces<\/strong>\u2013 These namespaces are at the local or inner function.<\/li>\n<\/ol>\n<p><a tabindex=\"0\">8. What are decorators in Python ?<\/a><\/p>\n<p>Decorators are used to add some design patterns to a function without changing its structure. Decorators generally are defined before the function they are enhancing. To apply a decorator we first define the decorator function. Then we write the function it is applied to and simply add the decorator function above the function it has to be applied to. For this, we use the @ symbol before the decorator.<\/p>\n<p><a tabindex=\"0\">9. What are Dict and List comprehensions ?<\/a><\/p>\n<p>Dictionary and list comprehensions are just another concise way to define dictionaries and lists.<\/p>\n<p>Example of list comprehension is-<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\tx=[i for i in range(5)]<\/code><\/pre>\n<p>The above code creates a list as below-<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\t4\n[0,1,2,3,4]<\/code><\/pre>\n<p>Example of dictionary comprehension is-<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\tx=[i : i+2 for i in range(5)]<\/code><\/pre>\n<p>The above code creates a list as below-<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\t[0: 2, 1: 3, 2: 4, 3: 5, 4: 6]<\/code><\/pre>\n<p><a tabindex=\"0\">10. What are the common built-in data types in Python ?<\/a><\/p>\n<p>The common built-in data types in python are-<\/p>\n<p><strong>Numbers<\/strong>\u2013 They include integers, floating-point numbers, and complex numbers. eg.\u00a01, 7.9,3+4i<\/p>\n<p><strong>List<\/strong>\u2013 An ordered sequence of items is called a list. The elements of a list may belong to different data types. Eg.\u00a0[5,\u2019market\u2019,2.4]<\/p>\n<p><strong>Tuple<\/strong>\u2013 It is also an ordered sequence of elements. Unlike lists , tuples are immutable, which means they can\u2019t be changed. Eg.\u00a0(3,\u2019tool\u2019,1)<\/p>\n<p><strong>String<\/strong>\u2013 A sequence of characters is called a string. They are declared within single or double-quotes. Eg.\u00a0\u201cSana\u201d,\u00a0\u2018She is going to the market\u2019, etc.<\/p>\n<p><strong>Set<\/strong>\u2013 Sets are a collection of unique items that are not in order. Eg.\u00a0{7,6,8}<\/p>\n<p><strong>Dictionary<\/strong>\u2013 A dictionary stores values in key and value pairs where each value can be accessed through its key. The order of items is not important. Eg.\u00a0{1:\u2019apple\u2019,2:\u2019mango}<\/p>\n<p><strong>Boolean<\/strong>\u2013 There are 2 boolean values-\u00a0<strong>True<\/strong>\u00a0and\u00a0<strong>False<\/strong>.<\/p>\n<p><a tabindex=\"0\">11. What is the difference between .py and .pyc files ?<\/a><\/p>\n<p>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. The interpreter converts the source .py files to .pyc files which helps by saving time.\u00a0You can get a better understanding with the\u00a0<a href=\"https:\/\/www.edureka.co\/microsoft-azure-data-engineering-certification-course-washington\" target=\"_blank\" rel=\"noopener\">Data Engineering Course in Washington<\/a>.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">12. What is slicing in Python ?<\/a><\/p>\n<p>Slicing is used to access parts of sequences like lists, tuples, and strings. The syntax of slicing is-[start:end:step]. The step can be omitted as well. When we write\u00a0[start:end]\u00a0this returns all the elements of the sequence from the start (inclusive) till the end-1 element. If the start or end element is negative i, it means the ith element from the end. The step indicates the jump or how many elements have to be skipped. Eg. if there is a list-\u00a0[1,2,3,4,5,6,7,8]. Then\u00a0[-1:2:2]\u00a0will return elements starting from the last element till the third element by printing every second element.i.e.\u00a0[8,6,4].<\/p>\n<p><a tabindex=\"0\">13. What are Keywords in Python ?<\/a><\/p>\n<p>Keywords in python are reserved words that have special meaning.They are generally used to define type of variables. Keywords cannot be used for variable or function names. There are following 33 keywords in python-<\/p>\n<ul>\n<li>And<\/li>\n<li>Or<\/li>\n<li>Not<\/li>\n<li>If<\/li>\n<li>Elif<\/li>\n<li>Else<\/li>\n<li>For<\/li>\n<li>While<\/li>\n<li>Break<\/li>\n<li>\u00a0As<\/li>\n<li>Def<\/li>\n<li>Lambda<\/li>\n<li>Pass<\/li>\n<li>Return<\/li>\n<li>True<\/li>\n<li>False<\/li>\n<li>Try<\/li>\n<li>With<\/li>\n<li>Assert<\/li>\n<li>Class<\/li>\n<li>Continue<\/li>\n<li>Del<\/li>\n<li>Except<\/li>\n<li>Finally<\/li>\n<li>From<\/li>\n<li>Global<\/li>\n<li>Import<\/li>\n<li>In<\/li>\n<li>Is<\/li>\n<li>None<\/li>\n<li>Nonlocal<\/li>\n<li>Raise<\/li>\n<li>Yield<\/li>\n<\/ul>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">14. What are Literals in Python and explain about different Literals<\/a><\/p>\n<p>A literal in python source code represents a fixed value for primitive data types. There are 5 types of literals in python-<\/p>\n<ol>\n<li><strong>String literals<\/strong>\u2013 A string literal is created by assigning some text enclosed in single or double quotes to a variable. To create multiline literals, assign the multiline text enclosed in triple quotes. Eg.name=\u201dTanya\u201d<\/li>\n<li><strong>A character literal<\/strong>\u2013 It is created by assigning a single character enclosed in double quotes. Eg.\u00a0a=\u2019t\u2019<\/li>\n<li><strong>Numeric literals<\/strong>\u00a0include numeric values that can be either integer, floating point value, or a complex number. Eg.\u00a0a=50<\/li>\n<li><strong>Boolean literals<\/strong>\u2013 These can be 2 values- either True or False.<\/li>\n<li><strong>Literal Collections<\/strong>\u2013 These are of 4 types-<\/li>\n<\/ol>\n<ol>\n<li>a) List collections-Eg.\u00a0a=[1,2,3,\u2019Amit\u2019]<\/li>\n<li>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0b) Tuple literals- Eg.a=(5,6,7,8)<\/li>\n<li>c) Dictionary literals- Eg.dict={1: \u2019apple\u2019, 2: \u2019mango, 3: \u2019banana`\u2019}<\/li>\n<li>d) Set literals- Eg.\u00a0{\u201cTanya\u201d, \u201cRohit\u201d, \u201cMohan\u201d}<\/li>\n<li>Special literal- Python has 1 special literal None which is used to return a null variable.<\/li>\n<\/ol>\n<p><a tabindex=\"0\">15. How to combine dataframes in pandas ?15. How to combine dataframes in pandas ?<\/a><\/p>\n<p>The dataframes in python can be combined in the following ways-<\/p>\n<ol>\n<li>Concatenating them by stacking the 2 dataframes vertically.<\/li>\n<li>Concatenating them by stacking the 2 dataframes horizontally.<\/li>\n<li>Combining them on a common column. This is referred to as joining.<\/li>\n<\/ol>\n<p>The concat() function is used to concatenate two dataframes. Its syntax is-\u00a0pd.concat([dataframe1, dataframe2]).<\/p>\n<p>Dataframes are joined together on a common column called a key. When we combine all the rows in dataframe it is union and the join used is outer join. While, when we combine the common rows or intersection, the join used is the inner join. Its syntax is-\u00a0pd.concat([dataframe1, dataframe2], axis=\u2019axis\u2019, join=\u2019type_of_join)<\/p>\n<p><a tabindex=\"0\">16. What are the new features added in Python 3.9.0.0 version ?<\/a><\/p>\n<p>The new features in Python 3.9.0.0 version are-<\/p>\n<ul>\n<li>\u00a0New Dictionary functions Merge(|) and Update(|=)<\/li>\n<li>New String Methods to Remove Prefixes and Suffixes<\/li>\n<li><strong>Type Hinting Generics in Standard Collections<\/strong><\/li>\n<li>New Parser based on PEG rather than LL1<\/li>\n<li>New modules like zoneinfo and graphlib<\/li>\n<li><strong>Improved Modules like ast, asyncio, etc.<\/strong><\/li>\n<li><strong>Optimizations such as optimized idiom for assignment, signal handling, optimized python built ins, etc.<\/strong><\/li>\n<li>Deprecated functions and commands such as deprecated parser and symbol modules, deprecated functions, etc.<\/li>\n<li>Removal of erroneous methods, functions, etc.<\/li>\n<\/ul>\n<p><a tabindex=\"0\">17. How is memory managed in Python ?<\/a><\/p>\n<p>Memory is managed in Python in the following ways:<\/p>\n<ol>\n<li>Memory management in python is managed by\u00a0<strong><em>Python private heap space<\/em><\/strong>. All Python objects and data structures are located in a private heap. The programmer does not have access to this private heap. The python interpreter takes care of this instead.<\/li>\n<li>The allocation of heap space for Python objects is done by Python\u2019s memory manager. The core API gives access to some tools for the programmer to code.<\/li>\n<li>Python also has an inbuilt garbage collector, which recycles all the unused memory and so that it can be made available to the heap space.<\/li>\n<\/ol>\n<p><a tabindex=\"0\">18. What is namespace in Python ?<\/a><\/p>\n<p>A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.<\/p>\n<p><a tabindex=\"0\">19. What is PYTHONPATH ?<\/a><\/p>\n<p>It is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">20. What are python modules ? Name some commonly used built-in modules in Python ?<\/a><\/p>\n<p>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.<\/p>\n<p>Some of the commonly used built-in modules are:<\/p>\n<ul>\n<li>os<\/li>\n<li>sys<\/li>\n<li>math<\/li>\n<li>random<\/li>\n<li>data time<\/li>\n<li>JSON<\/li>\n<\/ul>\n<p><a tabindex=\"0\">21. What are local variables and global variables in Python ?<\/a><\/p>\n<p><strong>Global Variables:<\/strong><\/p>\n<p>Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program.<\/p>\n<p><strong>Local Variables:<\/strong><\/p>\n<p>Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\ta=2\ndef add():\nb=3\nc=a+b\nprint(c)\nadd()<\/code><\/pre>\n<p><strong>Output:\u00a0<\/strong>5<\/p>\n<p>When you try to access the local variable outside the function add(), it will throw an error.<\/p>\n<p><a tabindex=\"0\">22. Is python case sensitive ?<\/a><\/p>\n<p>Yes. Python is a case sensitive language.<\/p>\n<p><a tabindex=\"0\">23. What is type conversion in Python ?<\/a><\/p>\n<p>Type conversion refers to the conversion of one data type into another.<\/p>\n<p><strong>int()<\/strong>\u00a0\u2013 converts any data type into integer type<\/p>\n<p><strong>float()<\/strong>\u00a0\u2013 converts any data type into float type<\/p>\n<p><strong>ord()<\/strong>\u00a0\u2013 converts characters into integer<\/p>\n<p><strong>hex(<\/strong>) \u2013 converts integers to hexadecimal<\/p>\n<p><strong>oct()<\/strong>\u00a0\u2013 converts integer to octal<\/p>\n<p><strong>tuple() \u2013\u00a0<\/strong>This function is used to\u00a0convert to a tuple.<\/p>\n<p><strong>set() \u2013\u00a0<\/strong>This function returns the\u00a0type after converting to set.<\/p>\n<p><strong>list() \u2013\u00a0<\/strong>This function is used to convert\u00a0any data type to a list type.<\/p>\n<p><strong>dict() \u2013\u00a0<\/strong>This function is used to convert a tuple of order (key, value) into a dictionary.<\/p>\n<p><strong>str() \u2013\u00a0<\/strong>Used to\u00a0convert integer into a string.<\/p>\n<p><strong>complex(real,imag) \u2013<\/strong>\u00a0This function converts real numbers to complex(real,imag) number.<\/p>\n<p><a tabindex=\"0\">24. How to install Python on Windows and set path variable ?<\/a><\/p>\n<p>To install Python on Windows, follow the below steps:<\/p>\n<ul>\n<li>Install python from this link:\u00a0<a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.python.org\/downloads\/<\/a><\/li>\n<li>After this, install it on your PC. Look for the location where PYTHON has been installed on your PC using the following command on your command prompt: cmd python.<\/li>\n<li>Then go to advanced system settings and add a new variable and name it as PYTHON_NAME and paste the copied path.<\/li>\n<li>Look for the path variable, select its value and select \u2018edit\u2019.<\/li>\n<li>Add a semicolon towards the end of the value if it\u2019s not present and then type %PYTHON_HOME%<\/li>\n<\/ul>\n<p><a tabindex=\"0\">25. Is indentation required in python ?<\/a><\/p>\n<p>Indentation is necessary for Python. It specifies a block of code. All code within loops, classes, functions, etc is specified within an indented block. It is usually done using four space characters. If your code is not indented necessarily, it will not execute accurately and will throw errors as well.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">26. What is the difference between Python Arrays and lists ?<\/a><\/p>\n<p>Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\timport array as arr\nMy_Array=arr.array(&#039;i&#039;,[1,2,3,4])\nMy_list=[1,&#039;abc&#039;,1.20]\nprint(My_Array)\nprint(My_list)<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>array(\u2018i\u2019, [1, 2, 3, 4]) [1, \u2018abc\u2019, 1.2]<\/p>\n<p><a tabindex=\"0\">27. What are functions in Python ?<\/a><\/p>\n<p>A function is a block of code which is executed only when it is called. To define a\u00a0<a href=\"https:\/\/www.edureka.co\/blog\/python-functions\" target=\"_blank\" rel=\"noopener\">Python function<\/a>, the\u00a0<strong>def<\/strong>\u00a0keyword is used.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\tdef Newfunc():\nprint(&quot;Hi, Welcome to Kaashi Infotech&quot;)\nNewfunc(); #calling the function<\/code><\/pre>\n<p><strong>Output:\u00a0<\/strong>Hi, Welcome to Kaashiv Infotech<\/p>\n<p><a tabindex=\"0\">28. What is __init__ ?<\/a><\/p>\n<p>__init__ is a method or constructor in Python. This method is automatically called to allocate memory when a new object\/ instance of a class is created. All classes have the __init__ method.<\/p>\n<p>Here is an example of how to use it.<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\tclass Employee:\ndef __init__(self, name, age,salary):\nself.name = name\nself.age = age\nself.salary = 20000\nE1 = Employee(&quot;XYZ&quot;, 23, 20000)\n# E1 is the instance of class Employee.\n#__init__ allocates memory for E1. \nprint(E1.name)\nprint(E1.age)\nprint(E1.salary)<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>XYZ<\/p>\n<p>23<\/p>\n<p>20000<\/p>\n<p><a tabindex=\"0\">29. What is a lambda function ?<\/a><\/p>\n<p>An anonymous function is known as a lambda function. This function can have any number of parameters but, can have just one statement.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\ta = lambda x,y : x+y\nprint(a(5, 6))<\/code><\/pre>\n<p><strong>Output:\u00a0<\/strong>11<\/p>\n<p><a tabindex=\"0\">30. What is self in Python ?<\/a><\/p>\n<p>Self is an instance or an object of a class. In Python, this is explicitly included as the first parameter. However, this is not the case in Java where it\u2019s optional.\u00a0 It helps to differentiate between the methods and attributes of a class with local variables.<\/p>\n<p>The self variable in the init method refers to the newly created object while in other methods, it refers to the object whose method was called.<\/p>\n<p><a tabindex=\"0\">31. How does break, continue and pass work ?<\/a><\/p>\n<table width=\"583\">\n<tbody>\n<tr>\n<td width=\"118\">Break<\/td>\n<td width=\"465\">Allows loop termination when some condition is met and the control is transferred to the next statement.<\/td>\n<\/tr>\n<tr>\n<td width=\"118\">Continue<\/td>\n<td width=\"465\">Allows skipping some part of a loop when some specific condition is met and the control is transferred to the beginning of the loop<\/td>\n<\/tr>\n<tr>\n<td width=\"118\">Pass<\/td>\n<td width=\"465\">Used when you need some block of code syntactically, but you want to skip its execution. This is basically a null operation. Nothing happens when this is executed.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a tabindex=\"0\">32. What does [::-1} do ?<\/a><\/p>\n<p>[::-1] is used to reverse the order of an array or a sequence.<\/p>\n<p><em>\u00a0<\/em><\/p>\n<p><em>For example:<\/em><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\timport array as arr\nMy_Array=arr.array(&#039;i&#039;,[1,2,3,4,5])\nMy_Array[::-1]<\/code><\/pre>\n<p><strong>Output<\/strong>:\u00a0array(\u2018i\u2019, [5, 4, 3, 2, 1])<\/p>\n<p>[::-1] reprints a reversed copy of ordered data structures such as an array or a list. the original array or list remains unchanged.<\/p>\n<p><a tabindex=\"0\">33. How can you randomize the items of a list in place in Python ?<\/a><\/p>\n<p>Consider the example shown below:<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\tfrom random import shuffle\nx = [&#039;Keep&#039;, &#039;The&#039;, &#039;Blue&#039;, &#039;Flag&#039;, &#039;Flying&#039;, &#039;High&#039;]\nshuffle(x)\nprint(x)<\/code><\/pre>\n<p>The output of the following code is as below.<\/p>\n<p>[\u2018Flying\u2019, \u2018Keep\u2019, \u2018Blue\u2019, \u2018High\u2019, \u2018The\u2019, \u2018Flag\u2019]<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">34. What are python iterators ?<\/a><\/p>\n<p>Iterators are objects which can be traversed though or iterated upon.<\/p>\n<p><a tabindex=\"0\">35. How can you generate random numbers in Python ?<\/a><\/p>\n<p>Random module is the standard module that is used to generate a random number. The method is defined as:<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\timport random\nrandom.random<\/code><\/pre>\n<p>The statement random.random() method return the floating-point number that is in the range of [0, 1). The function generates random float numbers. The methods that are used with the random class are the bound methods of the hidden instances. The instances of the Random can be done to show the multi-threading programs that creates a different instance of individual threads. The other random generators that are used in this are:<\/p>\n<ol>\n<li><strong>randrange(a, b)<\/strong>: it chooses an integer and define the range in-between [a, b). It returns the elements by selecting it randomly from the range that is specified. It doesn\u2019t build a range object.<\/li>\n<li><strong>uniform(a, b)<\/strong>: it chooses a floating point number that is defined in the range of [a,b).Iyt returns the floating point number<\/li>\n<li><strong>normalvariate(mean, sdev)<\/strong>: it is used for the normal distribution where the mu is a mean and the sdev is a sigma that is used for standard deviation.<\/li>\n<li><strong>The Random class<\/strong>\u00a0that is used and instantiated creates independent multiple random number generators.<\/li>\n<\/ol>\n<h3 data-start=\"214\" data-end=\"275\">Top Python Interview Questions for QA<\/h3>\n<p data-start=\"333\" data-end=\"392\">1. <strong data-start=\"340\" data-end=\"392\">What is Python and why is it used in QA testing?<\/strong><\/p>\n<p data-start=\"393\" data-end=\"651\"><strong data-start=\"393\" data-end=\"404\">Answer:<\/strong><br data-start=\"404\" data-end=\"407\" \/>Python is a high-level, interpreted programming language known for its readability and simplicity. In QA, it\u2019s used for writing automation scripts, building test frameworks, and integrating with tools like Selenium, PyTest, and Robot Framework.<\/p>\n<p data-start=\"658\" data-end=\"729\">2. <strong data-start=\"665\" data-end=\"729\">What are Python\u2019s key features that benefit test automation?<\/strong><\/p>\n<p data-start=\"730\" data-end=\"743\"><strong data-start=\"730\" data-end=\"741\">Answer:<\/strong><\/p>\n<ul data-start=\"744\" data-end=\"897\">\n<li data-start=\"744\" data-end=\"761\">\n<p data-start=\"746\" data-end=\"761\">Simple syntax<\/p>\n<\/li>\n<li data-start=\"762\" data-end=\"828\">\n<p data-start=\"764\" data-end=\"828\">Large library support (e.g., <code class=\"\" data-line=\"\">unittest<\/code>, <code class=\"\" data-line=\"\">pytest<\/code>, <code class=\"\" data-line=\"\">selenium<\/code>)<\/p>\n<\/li>\n<li data-start=\"829\" data-end=\"861\">\n<p data-start=\"831\" data-end=\"861\">Cross-platform compatibility<\/p>\n<\/li>\n<li data-start=\"862\" data-end=\"897\">\n<p data-start=\"864\" data-end=\"897\">Easy integration with CI\/CD tools<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"904\" data-end=\"970\">3. <strong data-start=\"911\" data-end=\"970\">What is the difference between <code class=\"\" data-line=\"\">is<\/code> and <code class=\"\" data-line=\"\">==<\/code> in Python?<\/strong><\/p>\n<p data-start=\"971\" data-end=\"984\"><strong data-start=\"971\" data-end=\"982\">Answer:<\/strong><\/p>\n<ul data-start=\"985\" data-end=\"1095\">\n<li data-start=\"985\" data-end=\"1013\">\n<p data-start=\"987\" data-end=\"1013\"><code class=\"\" data-line=\"\">==<\/code> compares <strong data-start=\"1001\" data-end=\"1011\">values<\/strong><\/p>\n<\/li>\n<li data-start=\"1014\" data-end=\"1095\">\n<p data-start=\"1016\" data-end=\"1095\"><code class=\"\" data-line=\"\">is<\/code> compares <strong data-start=\"1030\" data-end=\"1049\">object identity<\/strong> (i.e., whether they point to the same memory)<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1260\" data-end=\"1337\">4. <strong data-start=\"1267\" data-end=\"1337\">What is a Python dictionary, and how is it useful in QA scripting?<\/strong><\/p>\n<p data-start=\"1338\" data-end=\"1502\"><strong data-start=\"1338\" data-end=\"1349\">Answer:<\/strong><br data-start=\"1349\" data-end=\"1352\" \/>A dictionary is a key-value data structure. It\u2019s useful in QA for storing test data, configuration parameters, and mapping expected vs actual results.<\/p>\n<p data-start=\"1714\" data-end=\"1779\">5. <strong data-start=\"1721\" data-end=\"1779\">What is PyTest and why is it popular in QA automation?<\/strong><\/p>\n<p data-start=\"1780\" data-end=\"1955\"><strong data-start=\"1780\" data-end=\"1791\">Answer:<\/strong><br data-start=\"1791\" data-end=\"1794\" \/>PyTest is a robust testing framework for writing and running test cases. It supports fixtures, parameterized tests, and plugins like <code class=\"\" data-line=\"\">pytest-html<\/code> for reporting.<\/p>\n<p data-start=\"2514\" data-end=\"2594\">6. <strong data-start=\"2521\" data-end=\"2594\">What is the difference between <code class=\"\" data-line=\"\">assert<\/code> and <code class=\"\" data-line=\"\">soft assert<\/code> in testing?<\/strong><\/p>\n<p data-start=\"2595\" data-end=\"2606\"><strong data-start=\"2595\" data-end=\"2606\">Answer:<\/strong><\/p>\n<ul data-start=\"2607\" data-end=\"2775\">\n<li data-start=\"2607\" data-end=\"2660\">\n<p data-start=\"2609\" data-end=\"2660\"><code class=\"\" data-line=\"\">assert<\/code>: Stops execution when a condition fails.<\/p>\n<\/li>\n<li data-start=\"2661\" data-end=\"2775\">\n<p data-start=\"2663\" data-end=\"2775\">Soft assert (available via plugins\/frameworks): Continues even if an assertion fails, logging the error instead.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"2782\" data-end=\"2842\">7. <strong data-start=\"2790\" data-end=\"2842\">What are Python&#8217;s data types used in test cases?<\/strong><\/p>\n<p data-start=\"2843\" data-end=\"2854\"><strong data-start=\"2843\" data-end=\"2854\">Answer:<\/strong><\/p>\n<ul data-start=\"2855\" data-end=\"3040\">\n<li data-start=\"2855\" data-end=\"2894\">\n<p data-start=\"2857\" data-end=\"2894\"><code class=\"\" data-line=\"\">int<\/code>, <code class=\"\" data-line=\"\">float<\/code> \u2013 for numeric values<\/p>\n<\/li>\n<li data-start=\"2895\" data-end=\"2928\">\n<p data-start=\"2897\" data-end=\"2928\"><code class=\"\" data-line=\"\">str<\/code> \u2013 for string validation<\/p>\n<\/li>\n<li data-start=\"2929\" data-end=\"2962\">\n<p data-start=\"2931\" data-end=\"2962\"><code class=\"\" data-line=\"\">bool<\/code> \u2013 for condition checks<\/p>\n<\/li>\n<li data-start=\"2963\" data-end=\"3040\">\n<p data-start=\"2965\" data-end=\"3040\"><code class=\"\" data-line=\"\">list<\/code>, <code class=\"\" data-line=\"\">dict<\/code>, <code class=\"\" data-line=\"\">tuple<\/code>, <code class=\"\" data-line=\"\">set<\/code> \u2013 for storing test data or response payloads<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"214\" data-end=\"275\"><strong data-start=\"221\" data-end=\"275\">Final Thoughts on Basic Python Interview Questions and Answers<\/strong><\/h3>\n<p data-start=\"277\" data-end=\"670\">These <strong data-start=\"283\" data-end=\"319\">python basic interview questions<\/strong> form the foundation of any role involving Python. Whether you\u2019re aiming to become a Python developer, QA engineer, or automation tester, mastering the basics is non-negotiable. Always go beyond just memorizing answers\u2014<strong data-start=\"538\" data-end=\"563\">practice writing code<\/strong>, explore real-world scenarios, and gain hands-on experience with Python libraries relevant to your domain.<\/p>\n<p data-start=\"672\" data-end=\"1002\">If you&#8217;re serious about building a strong foundation in Python, consider enrolling in a <strong data-start=\"760\" data-end=\"829\">comprehensive <a class=\"cursor-pointer\" href=\"https:\/\/www.kaashivinfotech.com\/python-course\/\" target=\"_new\" rel=\"noopener\" data-start=\"776\" data-end=\"827\">Python course<\/a><\/strong>. A structured course will guide you through real-time projects, coding challenges, and industry-focused training\u2014ideal for freshers, QA professionals, and career switchers.<\/p>\n<p data-start=\"1004\" data-end=\"1150\">With consistent learning and practical exposure, you\u2019ll be well-prepared to <strong data-start=\"1080\" data-end=\"1114\">ace your next Python interview<\/strong> and build a successful tech career.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python basic interview questions are a great way to assess your understanding of Python\u2019s core concepts. Python is a general-purpose, dynamic, high-level, and interpreted programming language that is widely used across various domains\u2014from web development and data science to automation and testing. Python supports the Object-Oriented Programming (OOP) approach, making it easier to structure and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":9726,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[724],"tags":[767,770,764,763,768,759,758,761,760,762,769,766,765],"class_list":["post-2703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-questions","tag-python-coding-interview-questions","tag-python-coding-interview-questions-and-answers","tag-python-developer-interview-questions","tag-python-interview","tag-python-interview-preparation","tag-python-interview-questions","tag-python-interview-questions-and-answers","tag-python-interview-questions-and-answers-for-experienced","tag-python-interview-questions-and-answers-for-freshers","tag-python-interview-questions-for-freshers","tag-python-job-interview","tag-python-programming-interview-questions","tag-top-python-interview-questions"],"_links":{"self":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=2703"}],"version-history":[{"count":0,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2703\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media\/9726"}],"wp:attachment":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=2703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=2703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=2703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}