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

Python Basics: 15 Key Concepts Explained

Uploaded by

thenameisak84
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 views3 pages

Python Basics: 15 Key Concepts Explained

Uploaded by

thenameisak84
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

15 Python Basic Concepts (Simple Explanation)

1. Introduction to Python
Python is a high-level, easy, powerful programming language used for apps, AI, automation, websites,
and more.
Examples:
print("Hello Python")
x = 10
print("Value =", x)

2. Variables & Data Types


Variables store values. Data types define types of data.
Examples:
age = 20
name = "Akshay"
price = 45.5
is_passed = True

3. Input and Output


Input = data taken from user. Output = data shown to user.
Examples:
name = input("Enter name: ")
print("Hello", name)
a = int(input("Enter a number: "))
print("Square =", a*a)

4. Operators
Operators perform math, comparison, or logic.
Examples:
print(10 + 5)
print(10 > 5)
print(True and False)
print(2 in [1,2,3])

5. Conditional Statements
Run code only when condition is true.
Examples:
if 18 >= 18: print("Adult")
marks = 75
if marks >= 90: print("A"); elif marks>=60: print("B"); else: print("C")

6. Loops
Repeat actions many times.
Examples:
for i in range(3): print(i)
i=1
while i<=3: print(i); i+=1

7. Break, Continue, Pass


break stops loop, continue skips one loop, pass does nothing.
Examples:
for i in range(5):
if i==3: break
for i in range(5):
if i==2: continue

8. Strings
Text inside quotes.
Examples:
name="Akshay"; print([Link]())
msg="Hello"; print(msg+" World")

9. Lists
Ordered, changeable collection.
Examples:
fruits=["apple","banana"]; [Link]("orange")
nums=[1,2,3]; nums[1]=20

10. Tuples
Ordered, not changeable.
Examples:
t=(10,20,30); print(t[1])
colors=("red","green","blue"); print(len(colors))

11. Sets
Unique items, unordered.
Examples:
s={1,2,3,3}; print(s)
s={10,20}; [Link](30)

12. Dictionaries
Key-value pairs.
Examples:
student={"name":"Akshay","age":20}
print(student["name"])
student["age"]=21

13. Functions
Reusable block of code.
Examples:
def greet(): print("Hello")
def add(a,b): return a+b

14. Modules & Packages


Module=python file. Package=collection of modules.
Examples:
import math; print([Link](16))
import random; print([Link](1,10))

15. File Handling


Read/write files.
Examples:
open("[Link]","w").write("Hello")
print(open("[Link]","r").read())

You might also like