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

Python Programming Basics Guide

This document provides detailed notes on Python programming, covering essential topics such as input/output, variables, data types, type conversion, operators, conditional statements, loops, functions, data structures, file handling, exception handling, and object-oriented programming. Each section includes examples to illustrate the concepts. The notes serve as a comprehensive guide for understanding and using Python effectively.

Uploaded by

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

Python Programming Basics Guide

This document provides detailed notes on Python programming, covering essential topics such as input/output, variables, data types, type conversion, operators, conditional statements, loops, functions, data structures, file handling, exception handling, and object-oriented programming. Each section includes examples to illustrate the concepts. The notes serve as a comprehensive guide for understanding and using Python effectively.

Uploaded by

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

Python Detailed Notes with

Programming

1. Input and Output


Input → input() is used to take user input (always as string).
Output → print() is used to display data.

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

2. Variables
A variable stores data. No need to declare type (Python is dynamically typed).
x = 10
y = "Python"
z = 3.5

3. Data Types
- int → integers (10, -5)
- float → decimal numbers (3.14)
- str → text ("Hello")
- bool → True/False
- list → ordered collection [1,2,3]
- tuple → immutable collection (1,2,3)
- dict → key-value pairs {"name": "Sanjay"}
- set → unique unordered items {1,2,3}

a = 10 # int
b = 3.5 # float
c = "Python" # str
d = True # bool

4. Type Conversion
Converting one data type into another.

x = "100"
y = int(x) # string → int
print(y + 50) # Output: 150

5. Operators
- Arithmetic: +, -, *, /, %, **, //
- Relational: >, <, >=, <=, ==, !=
- Logical: and, or, not
- Assignment: =, +=, -=, *=

a = 10
b=3
print(a+b, a-b, a*b, a/b, a%b)

6. Conditional Statements
Used for decision making.

marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")

7. Loops
For Loop Example:

for i in range(1, 6):


print("Day", i)

While Loop Example:

n=5
while n > 0:
print("Countdown:", n)
n -= 1

8. Functions
Reusable block of code.

def greet(name):
return "Hello, " + name

print(greet("Amit"))
9. Data Structures
List Example:

fruits = ["apple", "banana", "mango"]


print(fruits[0]) # apple

Dictionary Example:

student = {"name": "Priya", "marks": 88}


print(student["name"])

10. File Handling


Writing to file and reading from file.

# Writing to file
with open("[Link]", "w") as f:
[Link]("Hello, Python!")

# Reading from file


with open("[Link]", "r") as f:
print([Link]())

11. Exception Handling


Handle errors gracefully.

try:
num = int("abc")
except ValueError:
print("Invalid number!")

12. Object-Oriented Programming (OOP)


OOP uses classes & objects.
Key Concepts: Encapsulation, Inheritance, Polymorphism, Abstraction.
class Student:
def __init__(self, name, marks):
[Link] = name
[Link] = marks

def display(self):
print(f"Name: {[Link]}, Marks: {[Link]}")

s1 = Student("Sanjay", 90)
[Link]()

You might also like