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

Python Basics Quick Summary

This document provides a quick overview of Python basics, covering topics such as data types, variables, conditional statements, loops, functions, built-in functions, file handling, exception handling, and object-oriented programming. It highlights Python's readability and simplicity while demonstrating various coding examples. The content is structured to serve as a foundational guide for beginners learning Python.

Uploaded by

aishuammu3092
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)
2 views3 pages

Python Basics Quick Summary

This document provides a quick overview of Python basics, covering topics such as data types, variables, conditional statements, loops, functions, built-in functions, file handling, exception handling, and object-oriented programming. It highlights Python's readability and simplicity while demonstrating various coding examples. The content is structured to serve as a foundational guide for beginners learning Python.

Uploaded by

aishuammu3092
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
You are on page 1/ 3

Python Basics - Quick Summary

1. Introduction to Python
 Python is a high-level, interpreted programming language.
 It's known for its readability, simplicity, and wide community support.

2. Data Types
 a = 10 # Integer
 b = 3.14 # Float
 name = "Apoorva" # String
 is_valid = True # Boolean
 fruits = ["apple", "banana", "cherry"] # List
 colors = ("red", "green", "blue") # Tuple
 person = {"name": "Apoorva", "age": 25} # Dictionary

3. Variables & Comments


 # This is a single-line comment
 """ This is a
multi-line comment """
 x=5
 y = "Hello"

4. Conditional Statements
 age = 18
 if age >= 18:
print("You are an adult")
 elif age > 13:
print("You are a teenager")
 else:
print("You are a child")

5. Loops
 # For loop
 for i in range(5):
print(i)
 # While loop
 count = 0
while count < 5:
print(count)
count += 1

6. Functions
 def greet(name):
return "Hello, " + name
 print(greet("Apoorva"))

7. Built-in Functions
 print(len("Python"))
 print(type(3.14))
 print(int("5"))

8. File Handling
 # Writing to a file
 with open("sample.txt", "w") as file:
file.write("Hello, Python!")
 # Reading from a file
 with open("sample.txt", "r") as file:
content = file.read()
print(content)

9. Exception Handling
 try:
x = 10 / 0
 except ZeroDivisionError:
print("Cannot divide by zero")
 finally:
print("Always runs")

10. Object-Oriented Basics


 class Person:
def __init__(self, name):
self.name = name
 def greet(self):
print("Hi, my name is", self.name)
 p = Person("Apoorva")
p.greet()

You might also like