Python Questions
5.34K subscribers
1 photo
7 links
Tasks for Beginners, Interview Questions, Regular expressions, simple coding problems, Quiz etc.

Useful Resources — »»» @python_resources_iGnani
Projects for Practice — »»» @python_projects_repository
Discussion Forum — »»» @python_programmers_club
Download Telegram
x = [1, 23, 'hello', 1]
type(x)
# What datatype of x? Explain?
Anonymous Quiz
5%
str
66%
list
6%
dict
8%
array
7%
tuple
4%
error
3%
Show me the answer
x, y = 5, 6
x+y == _____
#Which of the following statements is equal to x+y?
Anonymous Quiz
21%
x.__add(y)
34%
x.__add__(y)
9%
x.__ADD__(y)
5%
x.__ADD(y)
18%
None of the above
13%
Show me the answer
x = "Python World"
x[3] = 's'
# What is the value of x? Can you explain Why?
Anonymous Quiz
13%
Python World
6%
python world
52%
Pytson World
8%
Pyshon World
17%
Error
5%
Show me the answer
print('*', "abcdef".center(7), '*')

# What is the output? Can you Explain?
Anonymous Quiz
17%
*abcdef*
18%
* abcdef *
18%
* abcdef *
17%
* abcdef *
16%
Error
14%
Show me the answer
https://t.me/python_interview_questions/117

Only 14% got this correct.
 
True, False and None are capitalized, that is the first letter in these keywords start with a Capital letter.
The rest of all the other keywords are in lower case.
Hence, the correct answer is "
None of the above
".
print("abbcabcacabb".count('abb', 2, 11))

#What is the output of the above statement? Explain this statement?
Anonymous Quiz
27%
2
24%
1
14%
0
21%
Error
14%
Show me the answer
x = “python”+1+2+3

# What is the value of x? Explain?
Anonymous Quiz
27%
python123
11%
"python",1,2,3
21%
python6
34%
Error
3%
None of the above
4%
Show me the answer
print('xy'.isalpha())

#What is the output of the above code?
Anonymous Quiz
8%
xy
51%
True
21%
False
10%
xy.isalpha
4%
Error
6%
Show me the answer
print('1.1'.isnumeric())

#What is the output? Explain this.
Anonymous Quiz
7%
1
11%
1.1
44%
True
27%
False
5%
Error
1%
None of the above
5%
Show me the answer
x = (round(4.5) - round(-4.5))

#What is the value of x
Anonymous Quiz
35%
0
28%
9
8%
-9
16%
8
2%
-8
4%
None of the Above
7%
Show me the answer
print(r"\npython")

#What is the output? Explain Why?
Anonymous Quiz
39%
New line and 'python'
23%
\npython
10%
r\npython
6%
r,python
12%
Error
10%
Show me the answer
print('KLM'.maketrans('KLM', '123'))

What is the output? Explain the function maketrans()
Anonymous Quiz
11%
{65: 49, 66: 50, 67: 51}
26%
{75: 49, 76: 50, 77: 51}
14%
{75: 49, 66: 50, 77: 51}
17%
None of the above
31%
Show me the answer
print('iGnani'.translate({'i': '1', 'G': '2', 'n': '3', 'a': '4', 'i': '5'}))

#What is the output. Explain translate()
Anonymous Quiz
39%
123435
20%
12345
16%
iGnani
9%
Error
5%
None of the above
12%
Show me the answer
print('pyypyypypyppy'.replace('py', 'iG', 3))

#What is the output?
Anonymous Quiz
8%
pyypyypypyppy
25%
iGyiGyiGiGpiG
35%
iGyiGyiGpyppy
11%
Error
9%
None of the above
12%
Show me the answer
PyTip for the day:
Use the "enumerate" function to iterate over a sequence and get the index of each element.

Sometimes when you're iterating over a list or other sequence in Python, you need to keep track of the index of the current element. One way to do this is to use a counter variable and increment it on each iteration, but this can be tedious and error-prone.

A better way to get the index of each element is to use the built-in "enumerate" function. The "enumerate" function takes an iterable (such as a list or tuple) as its argument and returns a sequence of (index, value) tuples, where "index" is the index of the current element and "value" is the value of the current element. Here's an example:
 Iterate over a list of strings and print each string with its index
strings = ['apple', 'banana', 'cherry', 'date']
for i, s in enumerate(strings):
print(f"{i}: {s}")

In this example, we use the "enumerate" function to iterate over a list of strings. On each iteration, the "enumerate" function returns a tuple containing the index of the current string and the string itself. We use tuple unpacking to assign these values to the variables "i" and "s", and then print out the index and string on a separate line.

The output of this code would be:
 apple
1: banana
2: cherry
3: date

Using the "enumerate" function can make your code more concise and easier to read, especially when you need to keep track of the index of each element in a sequence.