Basics of Python Guide
Basics of Python Guide
1. What is Python?
3. Installing Python
print('Hello, World!')
5. Python Indentation
Python uses indentation (spaces or tabs) to define blocks of code instead of curly braces.
Example:
Python Learning Guide - Easy Points
if True:
print('This is indented')
6. Comments in Python
Example:
# This is a comment
7. Variables
Example:
x = 10
y = 'Hello'
8. Data Types
- int: integer
- str: text
Python Learning Guide - Easy Points
- bool: True/False
9. Type Casting
You can convert data types using functions like int(), float(), str().
Example:
x = int('5')
Example:
print('Hello', name)
11. Operators
- Arithmetic: +, -, *, /, %, **, //
12. Strings
Example:
s = 'Python'
print(s[0])
print(len(s))
13. Lists
Example:
fruits.append('cherry')
14. Tuples
Example:
t = (1, 2, 3)
15. Sets
Example:
Python Learning Guide - Easy Points
s = {1, 2, 3}
16. Dictionaries
Example:
Example:
if x > 0:
print('Positive')
18. Loops
Example:
for i in range(5):
print(i)
Python Learning Guide - Easy Points
19. Functions
Example:
return a + b
Example:
try:
x=1/0
except ZeroDivisionError: