python-interview-preperation-9
python-interview-preperation-9
Python Tutorials +
Python for Data Science + Data Science
Data Science Tutorials
Python Career Guides +
Categories
Python Learning Tutorials+
Projects
Machine
Programming
C Tutorials
150+ Python Interview
Courses
Python Interview Questions +
Cloud
Big Data Hadoop & Spark Scala
Python
Scala
Cloud Quiz
Big Data TutorialsTutorials +
Tutorials
Computing
Python Course
Android
Hadoop
Python
Java
AWS
Tutorials
Tutorials
Tutorials
Tutorials
Tutorials
Ecosystem Tutorials
Questions and Answers
for Freshers [Latest]
BI Tutorials
Blockchain
Big Data & Tutorials
Hadoop
ApacheTutorials
TensorFlow
Tableau
Spring Spark
Tutorials
Tutorials
Tutorials
SQL &Tutorials
Linux
Apache NoSQL
Kafka
Apache
Pandas
Power
SQL Tutorials
BI
Tutorials
Flink
Tutorials
Tutorials Free Python course with 35 real-time projects Start
IoT Tutorials
JavaScript
Apache Spark
Tutorials
& Scala Now!!
Apache Tutorials
Django
QlikView
Cassandra
Kafka
Tutorials
Tutorials
Tutorials
AngularJS
R TutorialsTutorials DataFlair is devoted to help Python learners become
Qlik Sense Tutorials
MongoDB successful in their Python careers. That’s why we are
SAS Tutorials publishing an interesting and helpful series of Python
SAP HANA Tutorials Interview Questions and Answers. In this series, you
AI Tutorials will get 150+ Python Interview Questions and
Answers in 3 different parts, that covers
Interpreted
Dynamically-typed
Object-oriented
Concise and simple
Free
Has a large community
>>> mylist=[1,3,3]
>>> mylist[1]=2
>>> mytuple=(1,3,3)
>>> mytuple[1]=2
mytuple[1]=2
>>> a,b=2,3
>>> min=a if a<b else b
>>> min
2
Hi
>>> mylist=[0,1,2,3,4,5,6,7,8]
>>> mylist[-3]
>>> mylist[-6:-1]
[3, 4, 5, 6, 7]
>>> myname='Ayushi'
>>> Myname
Myname
>>> 'AyuShi'.lower()
‘ayushi’
>>> 'AyuShi'.upper()
‘AYUSHI’
>>> 'AyuShi'.isupper()
False
>>> 'AYUSHI'.isupper()
True
>>> 'ayushi'.islower()
True
>>> '@yu$hi'.islower()
True
>>> '@YU$HI'.isupper()
True
True
copy(x)
>>> mydict=
{'a':1,'b':2,'c':3,'e':5}
>>> mydict.keys()
>>> (1,2,3,4,5)[2:4]
(3, 4)
>>> [7,6,8,5,9][2:]
[8, 5, 9]
>>> 'Hello'[:-1]
‘Hell’
>>> 'ayushi'.capitalize()
‘Ayushi’
>>> type(str.capitalize)
<class ‘method_descriptor’>
>>> '@yushi'.capitalize()
‘@yushi’
>>> 'Ayushi123'.isalnum()
True
>>> 'Ayushi123!'.isalnum()
False
>>> '123.3'.isdigit()
False
>>> '123'.isnumeric()
True
>>> 'ayushi'.islower()
True
>>> 'Ayushi'.isupper()
False
>>> 'Ayushi'.istitle()
True
True
>>> '123F'.isdecimal()
False
>>> import os
>>> os.getcwd()
‘C:\\Users\\lifei\\AppData\\Local\\Programs\\Python\\Python36-
32’
>>> type(os.getcwd)
<class ‘builtin_function_or_method’>
>>>
os.chdir('C:\\Users\\lifei\\Desktop
')
>>> os.getcwd()
‘C:\\Users\\lifei\\Desktop’
>>> a=[1,2,4]
>>> a.insert(2,3)
>>> a
[1, 2, 3, 4]
>>> a.reverse()
>>> a
[4, 3, 2, 1]
>>> a[::-1]
>>> a
[1, 2, 3, 4]
>>>
If you have worked with the IDLE, you will see this
prompt.
>>> if 3>1:
print("Hello")
print("Goodbye")
Hello
Goodbye
>>> max('flyiNg')
‘y’
The following are the ASCII values for all the letters
of this string-
f- 102
l- 108
y- 121
i- 105
N- 78
g- 103
>>> max('fly{}iNg')
‘}’
(Bonus: } – 125)
>>> complex(3.5,4)
(3.5+4j)
20
[2, 0, False]
>>> hash(3.7)
644245917
>>> hex(14)
‘0xe’
Enter a number7
‘7’
>>> len('Ayushi')
6
>>> locals()
>>> file=open('tabs.txt')
>>> word=’abcdefghij’
>>> word[:3]+word[3:]
>>> nums=
['one','two','three','four','five',
'six','seven']
>>> s=' '.join(nums)
>>> s
>>> list=[1,2,1,3,4,2]
>>> set(list)
{1, 2, 3, 4}
1. >>> roots={25:5,16:4,9:3,4:2,1:1}
2. >>> type(roots)
<class ‘dict’>
1. >>> roots[9]
{25: 5, 16: 4, 9: 3, 4: 2, 1: 1}
>>> 7//2
>>> 2**10
1024
>>> 13%7
>>> 3.5%1.5
0.5
>>> 'hi'<'Hi'
False
Greater than (>) If the value on the left is greater, it
returns True.
>>> 1.1+2.2>3.3
True
>>> 3.0<=3
True
>>> True>=False
True
Equal to (==) If the two values are equal, it returns
True.
>>> {1,3,2,2}=={1,2,3}
True
>>> True!=0.1
True
>>> False!=0.1
True
>>> a=7
>>> a+=1
>>> a
8
>>> a-=1
>>> a
>>> a*=2
>>> a
14
>>> a/=2
>>> a
7.0
>>> a**=2
>>> a
49.0
>>> a//=3
>>> a
16.0
>>> a%=4
>>> a
0.0
False
True
True
True
>>> 10 is '10'
False
True
>>> 3|2
>>> 3^2
>>> ~2
-3
>>> 1<<2
>>> 4>>2
>>> colors=['red','green','blue']
>>> type(colors)
<class ‘list’>
>>> name=('Ayushi','Sharma')
>>> name[0]='Avery'
name[0]=’Avery’
>>> squares={1:1,2:4,3:9,4:16,5:25}
>>> type(squares)
<class ‘dict’>
>>> type({})
<class ‘dict’>
Hi
>>> sayhi.__doc__
>>> int('227')
227
>>> type('227')
<class ‘str’>
>>> type(int('227'))
<class ‘int’>
Enter a number7
>>> type(a)
<class ‘str’>
>>> a*=2
>>> a
’77’
Enter a number7
>>> a*=2
>>> a
14
Q.43. What is a function?
3.5
24
>>> list(zip(['a','b','c'],
[1,2,3]))
>>> list(zip(('a','b','c'),
(1,2,3)))
[1, 3, 5, 7, 9]
>>> 'd' in
{'a':1,'b':2,'c':3,'d':4}.values()
False
>>> 4 in
{'a':1,'b':2,'c':3,'d':4}.values()
True
>>> 'AyuShi'.swapcase()
‘aYUsHI’
>>> i=0
>>> while s[i]!='t':
print(s[i],end=’’)
i+=1
I love Py
>>> for i in s:
if i==' ': continue
print(i,end='')
IlovePython
I love Python
I love Python
I love Python
I love Python
I love Python
I love Python
>>> bytes([2,4,8])
b’\x02\x04\x08′
>>> bytes(5)
b’\x00\x00\x00\x00\x00′
>>> bytes('world','utf-8')
b’world’
nums=[‘22’,’68’,’110’,’89’,’31’,’12’]
{‘first_name’:’Ayushi’,’second_name’:’Sharma’
>>> int(0b1010)
10
>>> bin(0xf)
‘0b1111’
>>> oct(8)
‘0o10’
>>> hex(16)
‘0x10’
>>> hex(15)
‘0xf’
([10],[123],[‘a’])
a. One argument
>>> list(range(5))
[0, 1, 2, 3, 4]
>>> list(range(-5))
[]
>>> list(range(0))
[]
b. Two arguments
>>> list(range(2,7))
[2, 3, 4, 5, 6]
>>> list(range(7,2))
[]
>>> list(range(-3,4))
>>> list(range(2,9,2))
[2, 4, 6, 8]
>>> list(range(9,2,-1))
[9, 8, 7, 6, 5, 4, 3]
>>> a,b=b,a
>>> a,b=2,3
>>> a,b=b,a
>>> a,b
(3, 2)
First –
Second –
7
7
counterfunc(7)
while(n==7):print(n)
KeyboardInterrupt
Encapsulation
Abstraction
Inheritance
Polymorphism
Data hiding
>>> tuple=(1,2,4)
>>> tuple
(1, 2, 4)
>>> 2+4j
(2+4j)
>>> [2,4,9]
[2, 4, 9]
>>> dict1={1:1,2:2}
>>> dict1
{1: 1, 2: 2}
17 RESPONSES
Comments 17 Pingbacks 0
Reply
LEAVE A REPLY
Comment *
Name * Email *
Post Comment
Home About us Contact us Terms and Conditions Privacy Policy Disclaimer Write For Us Success Stories