0% found this document useful (0 votes)
16 views8 pages

Python Test 1

python interview test 1

Uploaded by

dkhan9935
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Python Test 1

python interview test 1

Uploaded by

dkhan9935
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

PYTHON_TEST_1

1 What is Python? What are the benefits of using Python?


Python is a programming language with objects, modules, threads,
exceptions and automatic memory management. The benefits of pythons are
that it is simple and easy, portable, extensible, build-in data structure and it
is an open source.

2 How Python is interpreted?


Python language is an interpreted language. Python program runs directly
from the source code. It converts the source code that is written by the
programmer into an intermediate language, which is again translated into
machine language that has to be executed.

3 What are programming Language Paradigms?


There are two types of Programming Language Paradigms:
1. Imperative Paradigm
2. Declarative Paradigm
1. Imperative Paradigm:
It consists of commands for the computer to perform.
1. Procedural Programming Paradigm
It is based on the concept of using procedures. Example: C, Pascal
2. Object-oriented Programming Paradigm
It is based on the concept of "objects", Example: C++, JAVA
Declarative Paradigm:
A style of building the structure and elements of computer programs,without
describing its control flow.
1. Functional Programming Paradigm
It is the process of building software by composing pure functions.
Example: LISP (List Processing)
2. Logical Programming Paradigm:
It is largely based on formal logic Example: PROLOG (Programming in Logic)

4 Explain PYTHON Run Modes?


1 Interactive mode
2 Script mode

5 Python print() detailed Syntax:


print(value1, ..., sep=' ', end='\n', file=[Link], flush=False)
print() Parameters
objects - object to the printed.
sep - objects are separated by sep. Default value: ' '
end - end is printed at last
file - must be an object with write(string) method.
flush - If True, the stream is forcibly flushed. Default value: False
6. PSF, PEPs, PyPI stands for?
PSF ==> Python Software Foundation
PEPs ==> Python Enhancement Proposals
PyPI ==> Python Package Index

7 Write five implementations of the Python language?


1. CPython (Standard, implementation of Python)
2. Jython(Python for Java)
3. IronPython(Python for .NET)
4. Stackless (Python for concurrency)
5. PyPy(Python for speed)

8 Single Lone Underscore (_):


The most recent output value is automatically stored by the interpreter in a
special variable with the name "_".

9 Display list of Keywords and version commands?


import keyword
print([Link])

import sys
print ([Link])
or
import platform
platform.python_version()

10 What is Shebang?
The term shebang refers to the "#!" located at the top of many script files
that points to the path of the associated program. It has the following alias
Names:
1. She-bang
2. Hashbang
3. Pound-bang
4. Hash-pling
5. Crunchbang....etc..!!
The usage of #!/usr/bin/python plays a role if the script is executable, and
called without the preceding language.

11 Components of Pycharm:
It has mainly the following Components:
1. Menu or Dashboard
2. Project Panel
3. Code Editor
4. Console or Output Window

12 What is Anaconda?
Anaconda is a freemium open source distribution of the Python and R
programming languages for large-scale data processing, predictive analytics,
and scientific computing, that aims to simplify package management and
deployment

13 PIP List
List installed packages, including editables. Packages are listed in a case-
insensitive sorted order.
Syntax:
pip list [options]

14 What is an identifier?
An identifier is just the name of the variable. or An identifier as the label that
names a variable

15 What is CamelCase?
It has the following Alias Names:
1 Camel case
2 camelCase
3 CamelCase
4 camel caps
5 medial capitals etc.............!!
CamelCase is a naming convention in which a name is formed of multiple
words that are joined together as a single word with the first letter of each of
the multiple words capitalized for better readability.
Examples:"iPhone ", "eBay", "FedEx", "PayPal", etc...!!

16 Output of the following:


oct(32)'0o40'
hex(32) '0x20'
bin(32) '0b100000'

17 Output is 2*6**2  72

18 What is a literal in Python? List of Python Literals?


A Literal is a constant value. The literals include the string, unicode string,
integer, float, long, list, tuple and dictionary types.
Python support the following literals:
I. String literals:
String literals can be formed by enclosing a text in the quotes. We can use
both single as well as double quotes for a String.
[Link] literals:
Numeric literals can belong to following four different numerical types.
1 Int(signed integers)
2 Long(long integers)
3 float(floating point)
4 Complex(complex)

III. Boolean literals:


A Boolean literal can have any of the two values: True or False.
IV. Special literals.
Python contains one special literal i.e., None.
[Link] Collections.
Collections such as tuples, lists and Dictionary are used in Python.

19 How to Clear screen in Windows and Unix


1. Using Keyboard shortcut: (UNIX)
Press CTRL + L

2. print("\n"*100) (in Windows)


3. clear="\n"*100
print(clear)

20 Any five Python Core libraries for Data Science


Python's popularity for data science is largely due to the strength of its core
libraries
1. NumPy==> It is the fundamental package for scientific computing with
Python
2. SciPy ==> It contains modules for optimization, linear algebra,
integration, interpolation etc.!
3. pandas ==> It is providing high-performance, easy-to-use data structures
and data analysis tools
4 matplotlib ==> It is a Python 2D plotting library
5 IPython ==> It is an interactive command-line terminal for Python

21 The following output


1 0b1001000 decimal is  72
2 0o122 decimal is  82
3 '0x5c' decimal is  92

PYTHON_TEST_2
1. Output of the following?
print(tuple('PYTHON'))
print(tuple([1,2,3,4]))
ANS:
('P', 'Y', 'T', 'H', 'O', 'N')
(1, 2, 3, 4)

2. Output of the following?


c = ord('Apple')
print ("The ASCII Character is: ",c)
ANS:
TypeError: ord() expected a character, but string of length 5 found

3. Output of the following?


b=complex(1,2)
c = complex(2,3)
d=complex(3,4)
print(b+c-d)
ANS:
1j

4. Output of the following?


import math
print([Link](-45.17))
print([Link](100.12))
print([Link](100.72))
ANS
-46
101
100

5. Output of the following?


str1="Naresh i Technologies"
print(str1)
str1[0]='A'
print(str1)

ANS
Naresh i Technologies
TypeError: 'str' object does not support item assignment

6. Output of the following?


astring="Hello World 007!"
print([Link]("0"))
ANS
2
7. Format Symbol %x Indicates?
ANS
hexadecimal integer (lowercase letters)

8. Output of the following?


s = "**";
seq = ("98", "**", "11");
print([Link]( seq ))

ANS
98******11

9.1024 Zettabytes=1 Yottabyte (YB)

10. Output of the following?


a=[1,2,1,3,0,0,4,7,8,6]
b=[5,5,7,8,7,9,6,1,1,2]
s1=set(a)
s2=set(b)
print(s1^s2) # Numbers in s1 or s2 but not both
ANS
{0, 3, 4, 5, 9}

[Link] of the following?


a=100
b=100
a+=b
b+=a
print("The Result is: ",a)
a**=b
print("The Result is: ",b)

ANS
The Result is: 200
The Result is: 300

[Link] of the following?


a=9
b=5
print("Bitwise Exclusive is: ",a ^ b)
ANS
Bitwise Exclusive is: 12
13. Output of the following?
a = 15
print("Binary Left Shift is: ", a << 2)
print("Binary Right Shift is: ", a >> 2)

ANS
Binary Left Shift is: 60
Binary Right Shift is: 3

14. Output of the following?


x1=512
y1=215
print('x1 is y1',x1 is y1)
print('x1 is not y1',x1 is not y1)

ANS
x1 is y1 False
x1 is not y1 True

15) What is the difference between list and tuple?


Lists
The literal syntax of lists is shown by square brackets.
Lists are mutable.
Lists show order.
Tuples
The literal syntax of tuples is shown by parentheses.
Tuples are immutable.
Tuples shows structure.

16. Output of the following?


str1=12345
print(len(str1))
ANS
TypeError: object of type 'int' has no len()

17. Output of the following?


b = 0XB2
print(b)
print(hex(0XB2))
ANS:
178
0xb2

18. Output of the following?


tup = (('a', 1) ,('b', 2), ('c', 3))
c = dict(tup)
print (c)
ANS
{'a': 1, 'b': 2, 'c': 3}

You might also like