Introduction+to+Python+Programming+(programming-based)_new+size
Introduction+to+Python+Programming+(programming-based)_new+size
You are expected to handle and analyse large volumes of data to draw inferences, and Python serves as an easy and effective tool to run different
operations. It is widely used in the scientific and research communities because of the simple syntax and a rich collection of libraries dedicated to various
aspects of data science.
As part of Python programming, you covered:
Data and its types: integer, float, string, Boolean
Data structures such as list, tuples etc. used to store data in Python
Various operations that can be performed over lists, tuples, dictionaries and sets
Control structures to help in decision making such as if-else statements, for and while loop
Define functions to execute repetitive tasks in Python
Programming in Python
Common Interview Questions:
1. What is the difference between a module and a package in Python?
2. How to convert a number into a string?
3. What is lambda function in Python?
Basics of Python Data Structures in Python
4. Explain the difference between a list and a tuple?
1. Data Types 1. List
5. How do you change the data type of a list? 2. Arithmetic operations 2. Tuples
3. String 3. Dictionary
6. What is the difference between generators and iterators?
4. String Operations 4. Sets
7. What is the range() function and wha t are its parameters?
8. Is Python case-sensitive?
9. What are functions?
10. How do you do data abstraction in Python?
11. What are the escape sequences in Python? Control Structures in Functions
12. What is an Expression? Python 1. Comprehension
1. If-else statement 2. Lambda functions and
2. For loops it's use
3. While loops 3. Range
4. Comprehensions 4. Map, filter and reduce
functions
5. Functions
Introduction to Python Programming
Data Type Syntax Data Structures List Tuples Sets
Integer int Definitions Lists are like arrays but it can Tuples are containers for Contains all types of data with no duplicate
contains different types of data holding different types entry
Float float together whereas arrays can of values
hold same type of data
String str
Boolean bool Mutable/
Mutable Immutable Mutable
Immutable
Example list_1 = [1,2,3,4,5] tuple_1 = (1,2,3,4,5) set_1 = {1,2,3,4,5}
Arithmetic
list_1[1] #2nd value - 2 list_1[1] Is unordered: hence index of element
#Float division Indexing
#2nd value - 2 is not defined on sets
133//10 #13
Length len(list_1) #5 len(list_1) #5 len(list_1) #5
#Modulus division
133%10 #3 Sum of elements sum(list_1) #15 sum(tuple_1) #15 sum(set_1) #15
#PEMDAS rule min(list_1) #1 min(tuple_1) #1 min(set_1) #1
3*3-(4+3)//2 #6 Find min/max
max(list_1) #5 max(tuple_1) #5 max(set_1) #5
Generator For loop can be iterated on generators in While loop cannot be iterated on
Conditional statement: Support Python generators directly
If-else statement: To execute the true or the false part of a given Generator For loop can be iterated on generators in While loop cannot be iterated on
condition
Support Python generators directly
If-elif-else statement: Used for decision-making
Speed of
For loop is faster than while loop While loop is slower than for loop
a = float(input()) execution of code
if (a <= 20):
num = int(input('Integer value:')) num = int(input('Integer value:'))
print ('a is less or equal to 20')
if num>0: if num>0:
elif (a>20 and a <= 30): fac = 1 fac = 1
print ('a is in between 20 and 30') for i in range(1, num + 1): i = 1
elif (a>30 and a <= 40): Example: fac = fac * i while i <= num:
print('Answer', num) fac = fac * i
print ('a is in between 30 and 40') Finding factorial i = i + 1
elif num<0:
else: print('Invalid input') print('Answer:', fac)
print ('a is greater than 40') else: elif num<0:
print('Zero factorial is 1') print('Invalid input')
else:
print('Zero factorial is 1')
#The following methods are executed along with the for loop to iterate over each element in a list, set or dictionary
Function