0% found this document useful (0 votes)
8 views

python unit 1 to 5

This document provides an introduction to Python, covering its features, applications, and basic concepts such as data structures, functions, modules, and object-oriented programming. It includes explanations of Python's syntax, control flow statements, and various built-in functions and methods for lists, tuples, sets, and dictionaries. Additionally, it touches on libraries like Pandas for data manipulation and Tkinter for GUI programming.

Uploaded by

patilrudra142007
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)
8 views

python unit 1 to 5

This document provides an introduction to Python, covering its features, applications, and basic concepts such as data structures, functions, modules, and object-oriented programming. It includes explanations of Python's syntax, control flow statements, and various built-in functions and methods for lists, tuples, sets, and dictionaries. Additionally, it touches on libraries like Pandas for data manipulation and Tkinter for GUI programming.

Uploaded by

patilrudra142007
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
You are on page 1/ 10

1.

1 Introduction to Python

1. What is Python?
Python is a high-level, interpreted programming language used for general-purpose
programming.

2. Who developed Python and when?


Python was created by Guido van Rossum and released in 1991.

3. What are some key features of Python?


Easy syntax, interpreted, object-oriented, portable, free & open-source, and has large libraries.

4. What are the applications of Python?


Web development, data science, machine learning, automation, gaming, GUI apps, etc.

5. Name some popular Python IDEs.


IDLE, PyCharm, VS Code, Jupyter Notebook, Thonny.

6. Why is Python called a high-level language?


Because it is close to human language and easy to understand.

7. Is Python compiled or interpreted?


Python is interpreted – it runs line by line.

1.2 Python Building Blocks

8. What is indentation in Python?


Indentation means spaces/tabs used to define blocks of code (like inside if, for).

9. What are identifiers?


Identifiers are names given to variables, functions, classes, etc.

10. What is the difference between a variable and a keyword?


Variables store values; keywords are reserved words (like if, else) used by Python.

11. Name any 5 Python keywords.


if, else, while, def, return

12. How do you write comments in Python?


Single-line: # comment
Multi-line: ''' comment ''' or """ comment """

13. Are variable names case-sensitive?


Yes, age and Age are different variables

1.3 Basic Input and Output

14. What is the use of input() function?


It takes input from the user as a string.

15. What is the use of print() function?


It displays output on the screen.
16. How do you take integer input from the user?
Use int(input("Enter a number: "))

1.4 Operators in Python

18. What are the types of operators in Python?


Arithmetic, Relational, Assignment, Logical, Bitwise, Membership, Identity

19. What are arithmetic operators?


+, -, *, /, %, //, **

20. What is the difference between = and ==?


= is assignment; == checks equality.

21. What are logical operators?


and, or, not

22. What is a bitwise operator?


Operates on bits: &, |, ^, ~, <<, >>

23. What is a membership operator?


Checks if value exists in a sequence: in, not in

24. What is the difference between is and ==?


== checks value, is checks object identity (memory location)

1.5 Control Flow Statements

Conditional Statements

25. What is the use of if statement?


It runs a block of code if the condition is true.

26. What is if-else used for?


To choose between two blocks of code.

27. What is if-elif-else?


To check multiple conditions one by one.

28. What is a nested if?


An if statement inside another if.

Loops

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


while repeats until condition is false.
for loops over a range or sequence.

32. What is a nested loop?


A loop inside another loop.

33. What does range(1, 6) mean?


It gives numbers 1 to 5 (end is excluded).
Loop Control Statements

34. What is break used for?


To exit the loop early.

35. What is continue used for?


To skip the current loop iteration.

36. What is pass?


It does nothing – a placeholder.

37. Can we use else with loops?


Yes, it runs when loop completes without break.

Unit II: Data Structures in Python


2.1 List
1. What is a list in Python?
A list is an ordered collection of items. It can hold
different data types and is mutable (can be changed).
2. How do you define a list?
my_list = [1, 2, 3, 'apple']
3. How do you access list elements?
print(my_list[0]) # Output: 1
4. How can you update a value in a list?

my_list[1] = 10

5. How do you delete a value from a list?

del my_list[2]

6. What are basic list operations?


🔹 Concatenation, repetition, membership check, length:
7. List some built-in list functions/methods.
🔹 append(), insert(), remove(), pop(), sort(), reverse(), len()

2.2 Tuple

8. What is a tuple in Python?


🔹 A tuple is an ordered collection like a list, but it is immutable (cannot be changed).

9. How do you define a tuple?

my_tuple = (1, 2, 3)

10. How do you access values from a tuple?

print(my_tuple[0])

11. Can you update or delete values in a tuple?


🔹 No, tuples are immutable. You cannot change or delete their elements.

12. What are basic tuple operations?


🔹 Similar to lists: indexing, slicing, concatenation, repetition

13. Give some built-in tuple functions/methods.


🔹 len(), max(), min(), count(), index()

🔹 2.3 Set

14. What is a set in Python?


🔹 A set is an unordered collection of unique elements. Duplicates are not allowed.

15. How do you define a set?

my_set = {1, 2, 3}

16. How do you access set values?


🔹 Sets are unordered, so you can’t access by index, but you can loop through them:

17. How do you delete elements from a set?


🔹 Using remove(), discard(), or pop()

18. What are basic set operations?


🔹 Union, intersection, difference, subset:
19. List some built-in set functions/methods.
🔹 add(), remove(), discard(), union(), intersection(), clear()

2.4 Dictionary

20. What is a dictionary in Python?


🔹 A dictionary is a collection of key-value pairs. Keys are unique.

21. How do you define a dictionary?

my_dict = {'name': 'Alice', 'age': 25}

22. How do you access a value in a dictionary?

print(my_dict['name']) # Output: Alice

23. How do you update a dictionary value?

my_dict['age'] = 26

24. How do you delete a key-value pair in a dictionary?

del my_dict['age']

25. What are basic dictionary operations?


🔹 Accessing, updating, deleting, checking if key exists

26. List some built-in dictionary methods.


🔹 keys(), values(), items(), get(), update(), pop(), clear()

3.1 Functions

1. What is a function in Python?


🔹 A function is a block of reusable code that performs a specific task.

2. How do you define a function in Python?

def greet():

print("Hello!")

3. How do you call a function?

greet()

. What are function arguments?


🔹 Arguments are values passed to a function when calling it.
Example:

5. What is the use of the return statement?


🔹 It sends back the result from the function to the caller.

6. What is the scope of a variable?


🔹 Scope defines where a variable can be accessed:

• Local scope – inside function

• Global scope – outside function

7. What is a lambda function in Python?


🔹 A lambda is an anonymous (nameless) function with a single expression

3.2 Modules

8. What is a module in Python?


🔹 A module is a file containing Python code (functions, classes, variables) that you can reuse.

9. How do you create a user-defined module?


🔹 Save your code in a .py file. Example: mymodule.py

10. How do you import a module?

11. What are built-in modules in Python?


🔹 Modules that come pre-installed like math, random, datetime, etc.

13. What is a namespace?


🔹 A namespace is a place where variable names are stored.
Example: local, global, built-in namespaces.

14. What is scoping in Python?


🔹 Scoping defines where a variable can be accessed (Local, Enclosing, Global, Built-in = LEGB rule).
🔹 3.3 Python Packages

15. What is a package in Python?


🔹 A package is a folder containing multiple modules and a special __init__.py file.

16. How do you create a user-defined package?


🔹 Create a folder, add Python files (modules), and include __init__.py

17. How do you import a package?

18. What is the difference between a module and a package?

• A module is a single file (.py)

• A package is a folder with multiple modules

19. What are some built-in packages in Python?


🔹 Examples: os, sys, json, math, datetime

Unit - IV: Object Oriented Programming in Python

🔹 1. What is Object-Oriented Programming (OOP)?

Ans: OOP is a programming style where everything is grouped into objects and classes to make code
reusable and organized.

2. How do you create a class in Python?

4. What is a constructor in Python?

Ans: A constructor is a special method called __init__() that runs automatically when an object is
created.

🔹 5. What is the use of self in Python?


Ans: self refers to the current object of the class. It is used to access variables and methods.

. What is polymorphism?

Ans: It means one function or method can behave in different ways. Example: Same method name
doing different tasks.

🔹 8. What is method overloading?

Ans: Defining multiple methods with the same name but different parameters (Python does not
support it directly like Java, but can be done using default values).

🔹 9. What is method overriding?

Ans: When a child class changes the behavior of a method from its parent class.

0. What is data hiding or abstraction?

Ans: Hiding internal details and showing only necessary parts using private variables or methods
(with _ or __ prefix).

🔹 11. What is inheritance in Python?

Ans: One class can use properties and methods of another class.

🔸 Types of Inheritance:

• Single Inheritance: One parent, one child

• Multiple Inheritance: Multiple parents, one child

• Multilevel Inheritance: Parent → Child → Grandchild

Unit – V

5.1 Pandas

1. What is Pandas in Python?


Ans: Pandas is a Python library used for data analysis and data manipulation.

2. What is a Pandas Series?


Ans: A Series is a one-dimensional labeled array, like a column in Excel.

3. What is a DataFrame in Pandas?


Ans: A DataFrame is a two-dimensional table with rows and columns, like an Excel sheet.
4. How do you read a CSV file using Pandas?

5.2 Tkinter (GUI Programming)

5. What is Tkinter?
Ans: Tkinter is Python’s built-in library for creating Graphical User Interfaces (GUI).

6. Name some common Tkinter widgets.


Ans: Label, Entry, Button, RadioButton, CheckButton

7. Write a simple Tkinter program to display a window.

import tkinter as tk

win = tk.Tk()

win.mainloop()

8.What is the use of Entry widget?


Ans: It allows the user to input text.

5.3 MySQL Database Connection

9. How do you connect Python with MySQL?


Ans: By using the mysql-connector-python package.

10. How do you install MySQL connector

11. What is a cursor() in MySQL?


Ans: It helps execute SQL queries in Python.

2. What is the use of execute() method?


Ans: It runs SQL queries like SELECT, INSERT, etc.

You might also like