0% found this document useful (0 votes)
6 views9 pages

Python

Python is a high-level, interpreted programming language known for its easy syntax and versatility in web development, data science, AI, and automation. Key features include dynamic typing, platform independence, and a wide range of libraries. It supports various programming paradigms and emphasizes code readability through indentation.

Uploaded by

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

Python

Python is a high-level, interpreted programming language known for its easy syntax and versatility in web development, data science, AI, and automation. Key features include dynamic typing, platform independence, and a wide range of libraries. It supports various programming paradigms and emphasizes code readability through indentation.

Uploaded by

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

1. What is Python?

Definition
Python is a high-level, interpreted programming language that is easy to learn and used for
web development, data science, AI, and automation.

For interview:
“Python is easy to read and write, so beginners and students can learn programming quickly.”

2. Features of Python

Important points (very common interview question):

• Easy syntax (like English)

• Interpreted language (no compilation step)

• Platform independent (runs on Windows, Linux, Mac)

• Supports multiple paradigms (procedural, OOP)

• Large libraries (NumPy, Pandas, etc.)

Short answer:

“Python is simple, powerful, and widely used in real-world applications.”

3. Variables in Python

Definition:
A variable is a name used to store data in memory.

Example:
x = 10
name = "Ali"

Important Point:

• No need to declare data type

Interview Line:

“Python is dynamically typed, so we don’t need to declare variable type.”


4. Data Types in Python

Common types:

Type Example
int 10
float 10.5
str "Hello"
bool True/False
list [1,2,3]
tuple (1,2,3)
dict {"a":1}

5. Input and Output

Input:
name = input("Enter name: ")

Output:
print("Hello", name)

Interview Tip:

• input() always takes string by default

6. Operators in Python

Types:

1. Arithmetic → +, -, *, /

2. Relational → >, <, ==

3. Logical → and, or, not

Example:
a = 10
b = 5
print(a > b and b > 2)
7. Conditional Statements

Used for decision making

Example:
age = 18

if age >= 18:


print("Eligible")
else:
print("Not Eligible")

Interview Line:

“if-else is used to control program flow based on condition.”

8. Loops in Python

1. for loop
for i in range(5):
print(i)

2. while loop
i = 0
while i < 5:
print(i)
i += 1

Difference:

• for → fixed iterations

• while → condition-based

9. Functions in Python (VERY IMPORTANT)

Definition:
A function is a block of code that performs a specific task.

Example:
def add(a, b):
return a + b

print(add(2,3))

Types:

• Built-in (print, len)

• User-defined

Interview Line:

“Functions improve code reusability and readability.”

10. Types of Arguments

• Positional

• Default

• Keyword

Example:
def greet(name="Guest"):
print("Hello", name)

greet()
greet("Ali")

11. Scope of Variables

Two types:

• Local → inside function

• Global → outside function

Example:
x = 10 # global
def func():
y = 5 # local

Interview Question:
Difference between local and global variable

12. Exception Handling

Used to handle errors

Example:
try:
x = int(input("Enter number: "))
except:
print("Invalid input")

Interview Line:

“Exception handling prevents program crash.”

13. Indentation (VERY IMPORTANT IN PYTHON)

Python uses indentation instead of brackets

Example:
if True:
print("Hello")

Interview Line:

“Indentation defines block of code in Python.”


1. What is Python?

Answer:
Python is a high-level, interpreted programming language. It is easy to learn and used in many
areas like web development, data science, artificial intelligence, and automation.

For interview:

“Python is simple and readable, so it is very suitable for students and beginners.”

2. Why is Python popular?

Answer:
Python is popular because:

• It has simple syntax

• Easy to learn and use

• Large number of libraries

• Platform independent

• Used in many real-world applications

For interview:

“Python is popular because it is easy and powerful at the same time.”

3. What is the difference between list and tuple?

Answer:

List Tuple

Mutable (can change) Immutable (cannot change)

Uses [] Uses ()

Slower Faster
Example:
list1 = [1,2,3]
tuple1 = (1,2,3)

For Interview:

“List can be modified, but tuple cannot be changed after creation.”

4. What is a function?

Answer:
A function is a block of code that performs a specific task and can be reused.

Example:
def add(a, b):
return a + b

For Interview:

“Function helps in reducing code repetition and improves readability.”

5. What are types of arguments in Python?

Answer:
There are mainly three types:

1. Positional arguments

2. Default arguments

3. Keyword arguments

Example:
def greet(name="Guest"):
print(name)

For Interview:

“Default arguments allow us to pass value optionally.”


6. What is exception handling?

Answer:
Exception handling is used to handle errors in a program so that the program does not crash.

Example:
try:
x = int(input())
except:
print("Error")

For Interview:

“It makes the program more robust and user-friendly.”

7. What is the difference between for loop and while loop?

Answer:

For Loop While Loop

Used when iterations are known Used when condition is used

Simpler syntax More flexible

Example:
for i in range(5):
print(i)

For Interview:

“For loop is used for fixed iterations, while loop is used when condition is important.”

8. What is variable scope?

Answer:
Scope means where a variable can be used.

Types:

• Local → inside function


• Global → outside function

Example:
x = 10 # global

def func():
y = 5 # local

For Interview:

“Local variable is limited to function, global variable can be used anywhere.”

9. What is dynamic typing in Python?

Answer:
Dynamic typing means we do not need to declare the data type of a variable.

Example:
x = 10
x = "Hello"

For Interview:

“Python automatically detects the type of variable.”

10. What is indentation in Python?

Answer:
Indentation means spaces at the beginning of a line, which define the block of code.

Example:
if True:
print("Hello")

For Interview:

“Python uses indentation instead of braces to define code blocks.”

You might also like