Blog available for sell
This blog is available for sale. Please 'contact us' if interested.
Advertise with us

Python Interview Questions
41. What Is The Purpose Of Id() Function In Python?
A: The id() is one of the built-in functions in Python.
id(object)
It accepts one parameter and returns a unique identifier associated with the input object.
42. What does the *args do In Python?
A: We use *args as a parameter in the function header. It gives us the ability to pass variable number of arguments.
def myfun(*arg_list):  
    for arg in arg_list:  
        print (arg) 
    
myfun(1, 2, 3, 4)
1
2
3
4
43. What does the **kwargs do In Python?
A: We can also use the **kwargs syntax in a Python function declaration. It let us pass the variable number of arguments which can be named or keyworded.
def myfun(**kwargs):  
    for emp, age in kwargs.items(): 
        print ("%s's age is %s." %(emp, age)) 
    
myfun(John=25, Kalley=22, Tom=32)
John's age is 25.
Kalley's age is 22.
Tom's age is 32.
44. Does Python Have A Main() Method?
A: The main() is the entry point function which happens to be called first in most programming languages.

Since Python is interpreter-based, so it sequentially executes the lines of the code one-by-one.

Python also does have a Main() method. But it gets executed whenever we run our Python script either by directly clicking it or starts it from the command line.

We can also override the Python default main() function using the Python if statement
print("Welcome")
print("__name__ contains: ", __name__)
def main():
    print("Testing the main function")
if __name__ == '__main__':
    main()

Output:
Welcome
__name__ contains:  __main__
Testing the main function
45. What Does The __ Name __ Do In Python?
A: Since there is no main() function in Python, when the command to run a python program is given to the interpreter, the code that is at level 0 indentation is to be executed. However, before doing that, it will define a few special variables.

__name__ is one such special variable. If the source file is executed as the main program, the interpreter sets the __name__ variable to have a value “__main__”. If this file is being imported from another module, __name__ will be set to the module’s name.

__name__ is a built-in variable which evaluates to the name of the current module. Thus it can be used to check whether the current script is being run on its own or being imported somewhere else by combining it with if statement

46. What Is The Purpose Of “End” In Python?
A: Python’s print() function always prints a newline in the end. The print() function accepts an optional parameter known as the ‘end.’ Its value is ‘\n’ by default. We can change the end character in a print statement with the value of our choice using this parameter.
# Example: Print a space  instead of the new line in the end.
print("practice" , end = ' ')  
print("python") 

# Printing a dot in the end.
print("pythoncircle" , end = '.')  
print("com", end = ' ')

Output:
practice python
pythoncircle.com
47. What Does The Chr() Function Do In Python?
A: It returns the string denoting a character whose Unicode code point is an integer.

For example, the chr(122) returns the string ‘z’ whereas the chr(1212) returns the string ‘Ҽ’.
48. What Does The Ord() Function Do In Python?
A: The ord(char) in Python takes a string of size one and returns an integer denoting the Unicode code format of the character in case of a Unicode type object, or the value of the byte if the argument is of 8-bit string type.
>>> ord("z")
122
49. How Do You Use The Split() Function In Python?
A: Python’s split() function works on strings to cut a large piece into smaller chunks, or sub-strings. We can specify a separator to start splitting, or it uses the space as one by default.
str = 'pdf csv json'
print(str.split(" "))
print(str.split())

Output:
['pdf', 'csv', 'json']
['pdf', 'csv', 'json']




DigitalOcean Referral Badge

© 2024-2025 Python Circle   Contact   Sponsor   Archive   Sitemap