Python Practice Test

0%

What is Python?

Correct! Wrong!

Explanation:
General-purpose interpreted, interactive language, object-oriented and high-level programming language

Which license does the Python source code fall under?

Correct! Wrong!

Explanation:
Python source code is also available under GNU General Public License (GPL).

Who created Phyton?

Correct! Wrong!

Explanation:
Guido van Rossum is a Dutch programmer best known as the creator of the Python programming language, for which he was the "benevolent dictator for life" (BDFL) until he stepped down from the position in July 2018. He remained a member of the Python Steering Council through 2019, and withdrew from nominations for the 2020 election.

Which of the following is a Python environment variable that isn't valid?

Correct! Wrong!

Correct Answer : OPTION B, PYTHONLIBRARY

What specifically is PYTHONPATH?

Correct! Wrong!

Explanation:
It tells the Python interpreter where to locate the module files imported into a program

What is the meaning of PYTHONHOME?

Correct! Wrong!

Explanation:
It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.

What is the purpose of PYTHONSTARTUP?

Correct! Wrong!

Explanation:
PYTHONSTARTUPis an environment variable you will define specifying the location of the path to a python file. This python script will be run by python before starting the python interactive mode (interpreter). You can use it for various enhancements like preloading modules, setting colors.

What does the -d command line option do?

Correct! Wrong!

Explanation:
It provides debug output

What is PYTHONCASEOK, and how does it work?

Correct! Wrong!

Explanation:
The purpose of PYTHONCASEOK is to enable finding module files on filesystems which are case-insensitive such as FAT, or which behave in a case-insensitive manner from point of view of the programmer, such as NTFS on Windows.

Which of these naming conventions for Python identifiers is incorrect?

Correct! Wrong!

Explanation:
An identifier can start with a number

What does the following code provide as an output?
for x in range(0.5, 5.5, 0.5):
print(x)

Correct! Wrong!

Explanation:
We cannot use the float numbers in range() function. Please refer to the following articles

What does the following code output?
var = "James" * 2 * 3
print(var)

Correct! Wrong!

Explanation:
We can use * operator to repeat the string n number of times. Here in the above question, First, we repeated string two times, and again we repeated the output string three times.

Is it possible to utilize the "else" clause in loops?
as an example:
for i in range(1, 5):
print(i)
else:
print("this is else block statement" )

Correct! Wrong!

Explanation:
We can use the else block after the end of for/while loop. The else block is used to check the successful execution of a loop. If the loop executed successfully without any issues, the else block executes.

What is the output of the code below?
listOne = [20, 40, 60, 80]
listTwo = [20, 40, 60, 80]
print(listOne == listTwo)
print(listOne is listTwo)

Correct! Wrong!

Explanation:
Equal To operator == used to compare the values of two objects while The is operator compares the identity of two objects.

In Python, is a string immutable?
Whenever we modify the string, Python Always creates a new String and assigns a new string to that variable.

Correct! Wrong!

Explanation:
Yes, Strings are immutable in Python. You cannot modify string once created. If you change a string, Python builds a new string with the updated value and assigns it to the variable.
For example:
str1 = "first"
id(str1)
str1 = str1+ " Two"
id(str1)
Output:
140560663354704
140560640152496
Earlier str1 was pointing to memory address “140560663354704” now, it’s pointing to “140560640152496” which means Python created a new string after you updated it.

What does the following code output? sampleList = ["Jon", "Kelly", "Jessa"]
sampleList.append(2, "Scott")
print(sampleList)

Correct! Wrong!

Explanation:
The append() method appends an item to the end of the list. SO we cannot pass the index number to it.

What does the following code output?
var1 = 1
var2 = 2
var3 = "3"
print(var + var2 + var3)

Correct! Wrong!

Explanation:
We cannot add string and number together using + operator, either we can use + operator to concatenate a string or add numbers.

What does following code output?
str = "pynative"
print (str[1:3])

Correct! Wrong!

Explanation:
Remember, the index always starts at 0. Therefore, str [1 : 3] is “yn”

What does the following code output?
def calculate (num1, num2=4):
res = num1 * num2
print(res)
calculate(5, 6)

Correct! Wrong!

Explanation:
In Python, we can set default values for arguments. If the function is called without the argument the default value is used.

What does the following code output?
sampleSet = {"Jodi", "Eric", "Garry"}
sampleSet.add(1, "Vicki")
print(sampleSet)

Correct! Wrong!

Explanation:
The set is an unordered data structure. So you cannot access/add/remove its elements by index number.

What does the following code output?
for i in range(10, 15, 1):
print( i, end=', ')

Correct! Wrong!

Explanation:
Remember, the range doesn’t include a stop number in the output. Refer to Python range function

What does the following code output?
valueOne = 5 ** 2
valueTwo = 5 ** 3
print(valueOne)
print(valueTwo)

Correct! Wrong!

Explanation:
Using two multiplication symbols, we can make a power relationship in Python. We call ** operator as an exponent operator. That is, in the expression 5 ** 3, 5 is being raised to the 3rd power.

What does the following code output?
print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))

Correct! Wrong!

Explanation:>br> If we pass A zero value to bool() construtor, it will treat it as is false.
Any non-zero value is true.

What is print(type(0xFF)data )'s type?

Correct! Wrong!

Explanation:
We can represent integers in binary, octal and hexadecimal formats.
0b or 0B for Binary and base is 2
0o or 0O for Octal and base is 8
0x or 0X for Hexadecimal and base is 16

What data type does the following have?
aTuple = (1, 'Jhon', 1+3j)
print(type(aTuple[2:3]))

Correct! Wrong!

Explanation:
When we access tuple value using subscript atuple[start: end] operator, it will always return tuple even if we are accessing a single value using the range of indexes