0% found this document useful (0 votes)
8 views4 pages

Learn Python 1hour Notes Fixed

This document provides quick notes for learning Python in one hour, covering basics such as printing, variables, data types, conditions, loops, functions, lists, dictionaries, modules, classes, error handling, and file handling. It also includes bonus tips on indentation, comments, package installation, and popular libraries. Each section contains code examples to illustrate the concepts discussed.

Uploaded by

sachinananya0430
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 views4 pages

Learn Python 1hour Notes Fixed

This document provides quick notes for learning Python in one hour, covering basics such as printing, variables, data types, conditions, loops, functions, lists, dictionaries, modules, classes, error handling, and file handling. It also includes bonus tips on indentation, comments, package installation, and popular libraries. Each section contains code examples to illustrate the concepts discussed.

Uploaded by

sachinananya0430
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/ 4

Learn Python in 1 Hour - Quick Notes

1. Basics

Print something:

print("Hello, World!")

Variables:

x=5

name = "Alice"

Data Types:

- int (5), float (5.5), str ("hello"), bool (True/False), list, dict, tuple, set

Input from user:

name = input("Enter your name: ")

2. Conditions

if x > 0:

print("Positive")

elif x == 0:

print("Zero")

else:

print("Negative")

3. Loops

For loop:

for i in range(5):

print(i)

While loop:

while x > 0:
Learn Python in 1 Hour - Quick Notes

print(x)

x -= 1

4. Functions

def greet(name):

return f"Hello, {name}!"

print(greet("Alice"))

5. Lists

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

fruits.append("orange")

print(fruits[0]) # first item

Loop through list:

for fruit in fruits:

print(fruit)

6. Dictionaries

person = {"name": "Alice", "age": 25}

print(person["name"])

Add new key-value:

person["city"] = "New York"

7. Importing Modules

import math

print(math.sqrt(16))
Learn Python in 1 Hour - Quick Notes

8. Classes (OOP Basics)

class Person:

def __init__(self, name):

self.name = name

def greet(self):

print(f"Hi, I'm {self.name}")

p = Person("Alice")

p.greet()

9. Error Handling

try:

x = int(input("Enter a number: "))

except ValueError:

print("That's not a number!")

10. File Handling

Writing to file:

with open("file.txt", "w") as f:

f.write("Hello, file!")

Reading file:

with open("file.txt", "r") as f:

content = f.read()

print(content)

Bonus Tips
Learn Python in 1 Hour - Quick Notes

- Indentation matters (use 4 spaces).

- Comments: # this is a comment

- Pip: pip install package-name

- Popular libraries: numpy, pandas, flask, django

You might also like