Python Questions - Set 1 Flashcards

(50 cards)

1
Q

What is the difference between method and function ?

A

Method Associates with class object.
While function works its own

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to print Zen of python

A

import this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In which language Python is written

A

Python is written in C language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Python interpreter written in which Language

A

Python interpreter is written in C language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to interact Python code with Java code

A

We have to use Jython language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Python is interpreter based or compiler based

A

Python is interpreter based

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is interpreter

A

An interpreter is a program that directly executes the instructions in a high-level language, without converting it into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to convert python code to C code

A

We have to use Cython a language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which programming language is used by developers of python

A

Rpython,
Its used by programmers that develop python itself , since it doesn’t need an interpreter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to get this output without fsrtring ,
if n= 25
My age is 25

A

n = 25
print(“My age is “,n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to write long multiple line code on python console

A

print(“Hello”);\
print(“To”);\
print(“python”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are keyword arguments of print function, give example ?

A

end=” “
sep=” “

print(“My name is Sundy “, “Dog Khan “,sep=”<> “,end=”#”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the special character in Python

A

Backlash is an special character in python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are literals

A

Constant values or fixed value ,
Values that never change during the whole execution of program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the output of this code,
give reasons in support of ur answer ?

mynum = 0o123
type(mynum)
printy(mynum)

A

int
83

python assumes octal numbers as integers ,
so the code assigns the decimal value 83 to the variable myoctal, and then it prints the value of myoctal using the print function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to save octal number in variable

A

myOctalNumber = 0o123

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to save hexadecimal number in variable

A

myhexaNumber = 0x123

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to print object class of identifiers ?

A

We have to use type method()
a = 10
type(a)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to write below decimal number in short or scientific notation - 0.000005

A

5e-6 in decimal form = 0.000005

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How to write Boolean values in Python

A

True , False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Hello to “Python”
How to create this type of string constant

A

We have to use special character of python ,
the backslash character , or we use single quotes
Conversion
mystr = “Hello to "Python"”
mystr = ‘Hello to “Python”’ ‘

22
Q

Create an constant of octal number number , and print it to decimal

A

myoctal= 0o123 # it converted to base 10 first & then assighned to variable
print(“Decimal Equivalent is “,myoctal)

23
Q

What are the unary operators in Python

A

Operators which works on single operands.

Unary plus +
Unary minus -
Bitwise not ~

+x , -x ~x

24
Q

What are membership, identity & comparison operators in python ?

A

Membership Operator - not , not in
Identity operator - is , is not

Comparison operators - == , <= , >= , !=

25
How to write logical operators in Python ,
and , or , not print(1 and 0) print(1 or 0) print(not 1)
26
What is the output of print(not 22)
False
27
What is the output of print(22 or 0)
22
28
What is the output of print(not b)
name 'b' is not defined
29
What is the Presidence of operators in Python
In python we have eight levels of Presidence 1. Parenthesis () 2. Exponent ** 3. Unary Operators -x , +x , ~x 4. Multipication & Division Operators - * / % // 5. Addition & Substraction + , - 6. Bitwise operators - shift, AND, XOR, OR 7. Comparison , Identity , Membership Operators 8. Logical Operators
30
What are the division operators in Python
/ Division % Modulus // Floor Division
31
What are the bitwise operators in Python
<< Bitwise Left >> Right Shift & Bitwise AND ^ Bitwise XOR | Bitwise OR
32
What is the presidence of bitwise operators
1. Bitwise Shift 2. Bitwise AND 3. Bitwise XOR 4. Bitwise OR
33
What is the presidence of Logical Operators
1. not 2. and 3. or
34
What is the output of print(1 and 200) , give reason in support of ur answer
in a logical AND operation like "1 and 200," the result would be the second operand, which is 200. So, in this context, the output is indeed 200
35
How to write bitwise not operator
~x
36
How to write Bitwise AND
&
37
How to write Bitwise OR
|
38
How to write Bitwise XOR
^
39
How to write Bitwise Shift
>> Right Shift Left Shift <<
40
How to write Exponent operator
**
41
What is the output of this code , print(5 % 2)
The output is 1
42
What is the output of this code , print(5 // 2)
The output is 2
43
What is the output of this code , print(5 / 2)
The output is 2.5
44
What is the output of this code ? ``` print('My age is ' + 25) ```
It shows an error TypeError: can only concatenate str (not "int") to str The Correct way is . ``` print('My age is ' ,25) ```
45
How to remove \n default behaviour of print function
We have to use keyword argument, to remove \n default behaviour of print function ``` print("Hello to",end=" ") print("Python ") ```
46
How to print symbol between two  strings in single print statement
We have to use keyword argument, ``` print("Hello to","Python",sep="#") ```
47
What is the output of -6 / 4 ?
-1.5
48
What is the output of 6. // 4
1.0 Floor Division rounds down to the nearest integer,The actual result of 6 / 4 is 1.5 , but floor division rounds down to 1 .
49
What is the output of 6 // -4 Give reason in support of ur answer
-2 In Python, when you use the double forward slash // operator for division, it performs floor division, which means it rounds down the result to the nearest integer. When you perform the operation 6 // -4, it will give you the result of -2, because -1.5 (the exact division result) is rounded down to the nearest integer, which is -2.
50
What is the output of  ``` 10 - 6 ** 2 / 9 * 10 + 1 ```
-39