Category: Python Interview Questions


  • Q & A – Python Advanced

    Q & A – Python Advanced

    (1) How Are Arguments Passed By Value Or By Reference In python? Pass by value: A copy of the actual object is passed. Changing the value of the copy of the object will not change the value of the original object. Pass by reference: Reference to the actual object is passed. Changing the value of the new object will change the value of the original object. In Python, arguments are passed by reference, i.e., reference to the actual object is passed. Example-1: def appendNumber(array): array.append(4) arr = [1, 2, 3] # Mutable Object print(arr) appendNumber(arr) print(arr) [1, 2, 3] [1,

    Read More

  • Q & A – Python Miscellaneous.

    Q & A – Python Miscellaneous.

    (1) What is Python? What are the benefits of using Python What Is Python: Python is a high-level, interpreted, general-purpose programming language. Being a general-purpose language, it can be used to build almost any type of application with the right tools/libraries. Additionally, python supports objects, modules, threads, exception-handling, and automatic memory management which help in modelling real-world problems and building applications to solve these problems. Benefits Of Using Python: Python is a general-purpose programming language that has a simple, easy-to-learn syntax that emphasizes readability and therefore reduces the cost of program maintenance. Moreover, the language is capable of scripting, is

    Read More

  • Q & A – Python Dictionary

    Q & A – Python Dictionary

    (1) What Is A Python Dictionary? How Does It Work? Python Dictionary objects are data types that are enclosed in curly braces ‘{}’ and have key and value pairs and each pair is separated by a comma. The dictionary is mapped. Meaning since it has key and value pair, a meaningful key can save a lot of trouble for coders, like using an address key to save all the addresses, an id key for all id’s and so on. Moreover, as of Python >3.6, dictionaries also preserve the order. Example-1 student = {‘Name’:’Subrat’, ‘Subject’:’Math’, ‘Mark’:88} print(student) {‘Name’: ‘Subrat’, ‘Subject’: ‘Math’,

    Read More

  • Q & A – Python Set

    Q & A – Python Set

    (1) What Is A Set Data Structure? A Set is an unordered collection data type that is iterable, mutable and has no duplicate elements.  Set is represented by { } (values enclosed in curly braces) The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set.  This is based on a data structure known as a hash table. Since sets are unordered, we cannot access items using indexes as we do in lists. Example-1 st = {1,4,2,5,1,3,3,4} print(st) {1, 2, 3, 4,

    Read More

  • Q & A – Python Tuple

    Q & A – Python Tuple

    (1) What Is A Tuple Data Structure? Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. Tuples are used to store multiple items in a single variable. A tuple is a collection which is ordered and unchangeable. Example-1 tp = (1,’abc’,4.5,[9,8]) print(type(tp)) print(tp) <class ‘tuple’> (1, ‘abc’, 4.5, [9, 8]) (2) Find The Size Of The Tuple In Python. getsizeof() Function can be used to get the size of the tuple. The getsizeof() function belongs to the python’s sys module. Example-1 import sys

    Read More

  • Q & A – Python List

    Q & A – Python List

    (1) Check If A List Contains An Element. The in operator will return True if a specific element is in a list. lst = [‘Subrat’,’Arpita’,’Abhispa’,’Subhada’] ‘Subhada’ in lst True (2) How To Iterate Over 2+ Lists At The Same Time. You can zip() lists and then iterate over the zip object. A zip object is an iterator of tuples. Below we iterate over 3 lists simultaneously and interpolate the values into a string. name = [‘Snowball’, ‘Chewy’, ‘Bubbles’, ‘Gruff’] animal = [‘Cat’, ‘Dog’, ‘Fish’, ‘Goat’] age = [1, 2, 2, 6] z = zip(name, animal, age) for i, j, k in z: print(f"Name: {i} Animal: {j} Age: {k}")

    Read More

  • Q & A – Python Numbers

    Q & A – Python Numbers

    (1) Check If A Number Is Positive, Negative or 0. num = float(input(‘Enter A Number ‘)) if num > 0: print(‘Positive Number’) elif num < 0: print(‘Negative Number’) else: print(‘Zero’) (2) Check If A Number Is Odd or Even. num = float(input(‘Enter A Number’)) if num % 2 == 0: print(‘Even Number’) else: print(‘Odd Number’) (3) Check A Year Is Leap Year Or Not. We have discussed above, we know that because the Earth rotates about 365.242375 times a year but a normal year is 365 days, something has to be done to “catch up” the extra 0.242375 days a

    Read More

  • Q & A – Python String

    Q & A – Python String

    (1) What Is A String Datatype? A String is a collection of a sequence of characters. A String can contain Alphabetic, Numeric, or Special characters. A String variable is enclosed within a single(”) or double quote(“”). A String type in Python is of the ‘str’ type. Example-1 name = ‘Subrat Kumar Sahoo’ print(name) Subrat Kumar Sahoo Example-2 password = "hallo@123" print(password) hallo@123 Example-3 country = ‘India’ print(country) India (2) How To Check Existence Of A Character Or A Sub-string In A String? You can use ‘in’ keyword to check the existence of a sub-string in a string. Example-1 "pass" in

    Read More

  • Python Interview Questions

    No posts found.

    Read More