Python Learning Guide - Easy Points
1. What is Python?
Python is an interpreted, high-level, general-purpose programming language. It emphasizes code readability
and simplicity. Developed by Guido van Rossum and released in 1991.
2. Why Learn Python?
- Simple and readable syntax
- Large community support
- Versatile: web development, data science, automation, etc.
- Plenty of libraries and frameworks
3. Installing Python
You can download Python from the official website: https://www.python.org/
Use an IDE like VS Code, PyCharm, or run scripts in terminal/command prompt.
4. Hello World Program
To print 'Hello, World!' in 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
- Single-line comment: starts with #
- Multi-line comment: use triple quotes ''' or """
Example:
# This is a comment
7. Variables
Variables are created when you assign a value.
Example:
x = 10
y = 'Hello'
Python is dynamically typed, so no need to declare the type.
8. Data Types
- int: integer
- float: decimal number
- str: text
Python Learning Guide - Easy Points
- bool: True/False
- list, tuple, set, dict: collections
9. Type Casting
You can convert data types using functions like int(), float(), str().
Example:
x = int('5')
10. Taking User Input
Use input() to take input from the user.
Example:
name = input('Enter your name: ')
print('Hello', name)
11. Operators
- Arithmetic: +, -, *, /, %, **, //
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
12. Strings
Strings are sequences of characters.
Python Learning Guide - Easy Points
Example:
s = 'Python'
print(s[0])
print(len(s))
13. Lists
Lists are ordered, mutable collections.
Example:
fruits = ['apple', 'banana']
fruits.append('cherry')
14. Tuples
Tuples are ordered, immutable collections.
Example:
t = (1, 2, 3)
15. Sets
Sets are unordered collections of unique elements.
Example:
Python Learning Guide - Easy Points
s = {1, 2, 3}
16. Dictionaries
Dictionaries store data in key-value pairs.
Example:
d = {'name': 'Alice', 'age': 25}
17. Conditional Statements
Use if, elif, else to control flow.
Example:
if x > 0:
print('Positive')
18. Loops
- for loop: for item in collection
- while loop: while condition
Example:
for i in range(5):
print(i)
Python Learning Guide - Easy Points
19. Functions
Defined using def keyword.
Example:
def add(a, b):
return a + b
20. Error Handling
Use try-except blocks to handle errors.
Example:
try:
x=1/0
except ZeroDivisionError:
print('Cannot divide by zero')