0% found this document useful (0 votes)
1 views5 pages

Merged Python Notes

The document provides a comprehensive overview of Python programming concepts, including variables, data types, input/output, control structures, functions, and object-oriented programming. Each concept is explained with theoretical definitions and practical code examples. Additionally, it covers advanced topics like modules, file handling, and exception handling.

Uploaded by

devaraj72003
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)
1 views5 pages

Merged Python Notes

The document provides a comprehensive overview of Python programming concepts, including variables, data types, input/output, control structures, functions, and object-oriented programming. Each concept is explained with theoretical definitions and practical code examples. Additionally, it covers advanced topics like modules, file handling, and exception handling.

Uploaded by

devaraj72003
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

■ Merged Python Notes (Theory + Code)

1. Variables — Theory
A variable is a name used to store a value. Python automatically detects the type based on what
you assign.

Example:
name = 'Deva'
age = 20

2. Data Types — Theory


Python supports integers, floats, strings, and booleans for handling different kinds of data.

Example:
price = 199.99
is_valid = True

3. Input / Output — Theory


Input allows user interaction while output displays information back to the user.

Example:
name = input("Enter your name: ")
print("Hello", name)

4. Type Casting — Theory


Type casting is the process of converting a value from one data type to another.

Example:
age = int(input("Enter age: "))
print(age + 1)

5. Operators — Theory
Operators perform arithmetic, comparison, and logical operations in Python.

Example:
print(10 > 5)

6. Strings — Theory
Strings are sequences of characters and are immutable in Python.

Example:
text = "python"
print([Link]())
7. List — Theory
Lists are ordered, changeable collections that allow duplicate values.

Example:
fruits = ["apple", "banana"]
[Link]("mango")

8. Tuple — Theory
Tuples are ordered but immutable collections, meaning they cannot be modified after creation.

Example:
colors = ("red", "green", "blue")

9. Dictionary — Theory
Dictionaries store data as key–value pairs, allowing fast access using keys.

Example:
person = {"name": "Deva", "age": 20}

10. Set — Theory


Sets store unique values and do not maintain order.

Example:
nums = {1, 2, 2, 3}

11. If / elif / else — Theory


Conditional statements allow programs to make decisions based on conditions.

Example:
age = 18
if age >= 18:
print('Adult')

12. For Loop — Theory


A for loop is used when the number of repetitions is known.

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

13. While Loop — Theory


A while loop continues executing as long as its condition is true.

Example:
count = 1
while count <= 3:
count += 1

14. Break / Continue — Theory


Break stops a loop entirely, while continue skips the current iteration.

Example:
# break and continue examples

15. Functions — Theory


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

Example:
def greet():
print('Hello')

16. Parameters / Arguments — Theory


Parameters are placeholders inside a function, while arguments are actual values passed to it.

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

17. Return Statement — Theory


The return statement allows a function to send a result back to where it was called.

Example:
def square(n):
return n * n

18. Default Arguments — Theory


Default arguments provide values when no value is supplied by the user.

Example:
def welcome(name='Guest'):
print(name)

19. *args — Theory


*args allows a function to accept any number of positional arguments.

Example:
def total(*n):
print(sum(n))

20. **kwargs — Theory


**kwargs allows a function to accept any number of keyword arguments.

Example:
def details(**info):
print(info)

21. List Comprehension — Theory


A short and readable way to create lists using expressions.

Example:
nums = [x*2 for x in range(5)]

22. Dictionary Comprehension — Theory


A compact way to create dictionaries using loops and expressions.

Example:
square = {x: x*x for x in range(3)}

23. Stack — Theory


A stack follows the Last-In, First-Out method.

Example:
stack = []
[Link](10)
[Link]()

24. Queue — Theory


A queue follows the First-In, First-Out rule.

Example:
from collections import deque

25. String Slicing — Theory


Slicing extracts a portion of a string using index positions.

Example:
text[0:3]

26. String Methods — Theory


String methods allow modifications like capitalization and replacement.

Example:
"hello".capitalize()

27. f-strings — Theory


f-strings allow easy and readable string formatting.

Example:
f"My name is {name}"

28. Class & Object — Theory


A class is a blueprint, and an object is an instance created from that blueprint.

Example:
class Student: ...

29. Inheritance — Theory


Inheritance allows one class to use features of another class.

Example:
class Dog(Animal): ...

30. Modules — Theory


A module is a Python file containing reusable code.

Example:
import math

31. File Handling — Theory


File handling lets Python create, read, update, and delete files.

Example:
Modes: r, w, a, x

32. Exception Handling — Theory


Exception handling manages errors gracefully using try and except blocks.

Example:
try/except, else, finally

You might also like