October 11, 2018

Sreekanth B

OpenText Most Frequently Asked Python Latest Interview Questions Answers

How will you get a space-padded string with the original string left-justified to a total of width columns?

just(width[, fillchar]) − Returns a space-padded string with the original string left-justified to a total of width columns.

How will you convert a string to all lowercase?

lower() − Converts all uppercase letters in string to lowercase.

How will you remove all leading whitespace in string?

strip() − Removes all leading whitespace in string.

How will you get the max alphabetical character from the string?

max(str) − Returns the max alphabetical character from the string str.

How will you get the min alphabetical character from the string?

min(str) − Returns the min alphabetical character from the string str.

How will you replaces all occurrences of old substring in string with new string?

replace(old, new [, max]) − Replaces all occurrences of old in string with new or at most max occurrences if max given.
OpenText Most Frequently Asked Python Latest Interview Questions Answers
OpenText Most Frequently Asked Python Latest Interview Questions Answers

How will you remove all leading and trailing whitespace in string?


strip([chars]) − Performs both lstrip() and rstrip() on string.

How will you change case for all letters in string?

swapcase() − Inverts case for all letters in string.

How will you get titlecased version of string?

title() − Returns “titlecased” version of string, that is, all words begin with uppercase and the rest are lowercase.

How will you convert a string to all uppercase?

upper() − Converts all lowercase letters in string to uppercase.

How will you check in a string that all characters are decimal?

isdecimal() − Returns true if a unicode string contains only decimal characters and false otherwise.

What is the difference between del() and remove() methods of list?

To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know.

What is the output of len([1, 2, 3])?

3.

What is the output of [1, 2, 3] + [4, 5, 6]?

[1, 2, 3, 4, 5, 6]

What is the output of [‘Hi!’] * 4?

[‘Hi!’, ‘Hi!’, ‘Hi!’, ‘Hi!’]

What is the output of 3 in [1, 2, 3]?

True

What is the output of for x in [1, 2, 3]: print x?

3: 1 2 3

What is the output of L[2] if L = [1,2,3]?

3, Offsets start at zero.

What is the output of L[-2] if L = [1,2,3]?

 L[-1] = 3, L[-2]=2, L[-3]=1

What is the output of L[1:] if L = [1,2,3]?

2, 3, Slicing fetches sections.

How will you compare two lists?

cmp(list1, list2) − Compares elements of both lists.

How will you get the length of a list?

len(list) − Gives the total length of the list.

How will you get the max valued item of a list?

max(list) − Returns item from the list with max value.

How will you get the min valued item of a list?

min(list) − Returns item from the list with min value.

How do you print the sum of digits from 1 to 50 in Python?

print(sum(range(1,51))

This command would print in the sum of digits from 1 to 50

What is PEP 8 in Python?

PEP 8 is a set of recommendations about writing Python Code so as to make it readable and useful for other programmers. It is more of a coding convention.
45. What is a Decorator in Python?

Decorators allow you to wrap a method or a class function that executes a set of code lines before or after the execution of the original code. Decorator also allows to inject or modify code in methods or classes.

What is Django Framework in Python?

Django is a high-level Python framework which is used primarily for Web Development. This framework encourages fast and efficient development with pragmatic and clean design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Subscribe to get more Posts :