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

Easy Python Notes

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)
2 views5 pages

Easy Python Notes

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

Easy Python Notes (Beginner Friendly)

1. Variables

Variables store data in Python.


a = 10
name = "Micky"
price = 99.5
Rules for Variable Names

Allowed:
python = 1
_python = 1
python1 = 1
py_thon = 1

Not Allowed:
1python = 1
if = 1
py@thon = 1

2. Comments

Comments are used to explain code.


# Single line comment
'''
Multi-line comment
'''

3. Data Types

Python supports different data types like int, float, string, list, tuple, set, and dictionary.

4. Strings
name = "Python"
print(name[0])
print(len(name))
5. Type Conversion
a = 5
b = "5"
c = a + int(b)
print(c)

6. Operators

Arithmetic, Comparison, and Logical Operators are used in Python.

7. Input and Output


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

8. If-Else Statements
x = 10
if x > 5:
print("Greater")
else:
print("Smaller")

9. Loops

For Loop
for i in range(5):
print(i)

While Loop
x = 1
while x <= 5:
print(x)
x += 1

10. List
l1 = [1,2,3]
[Link](4)
11. Tuple

Tuple is immutable.

12. Set

Set stores unique values.

13. Dictionary
student = {
"name": "Micky",
"roll": 10
}

14. Functions
def add(a, b):
return a + b

15. Recursion
def factorial(n):
if n == 1:
return 1
return n * factorial(n-1)

16. File Handling


file = open("[Link]", "r")
print([Link]())

17. Exception Handling


try:
print(10/0)
except ZeroDivisionError:
print("Error")
18. Classes and Objects
class Student:
name = "Micky"

19. Constructor
class Student:
def __init__(self, name):
[Link] = name

20. Inheritance
class Parent:
pass
class Child(Parent):
pass

21. Lambda Function


square = lambda x: x*x

22. Iterators
l = [1,2,3]
it = iter(l)
print(next(it))

23. Generators
def gen():
yield 1
yield 2

24. Closure
def outer(x):
def inner():
print(x)
return inner

25. Decorators
def deco(func):
def inner():
func()
print("Welcome")
return inner

Common Errors

• SyntaxError

• TypeError

• IndexError

• NameError

• IndentationError

Best Way to Learn Python

• Read concepts

• Practice code

• Build small projects

You might also like