Basic Python Topics with Definitions
1. Variables
Used to store data values. In Python, variables are created when you assign a value to them.
Example: x = 10
2. Data Types
The type of value a variable holds (e.g., integer, string, float, list).
Examples:
- Integer: 5
- Float: 3.14
- String: "Hello"
- Boolean: True or False
3. Operators
Symbols used to perform operations on variables and values.
Types:
- Arithmetic: +, -, *, /
- Comparison: ==, !=, <, >
- Logical: and, or, not
4. Conditional Statements
Used to make decisions in code.
Example:
if x > 0:
print("Positive")
Basic Python Topics with Definitions
elif x == 0:
print("Zero")
else:
print("Negative")
5. Loops
Used to repeat a block of code.
Types:
- for loop:
for i in range(5): print(i)
- while loop:
while x > 0: x -= 1
6. Functions
A block of reusable code.
Example:
def greet(name):
return "Hello " + name
7. Lists
Ordered and changeable collection of items.
Example: fruits = ["apple", "banana", "cherry"]
8. Tuples
Basic Python Topics with Definitions
Ordered but unchangeable collection of items.
Example: coordinates = (10, 20)
9. Dictionaries
Collection of key-value pairs.
Example:
person = {"name": "Alice", "age": 25}
10. Classes and Objects
Python is an object-oriented language. Classes are blueprints for objects.
Example:
class Person:
def __init__(self, name):
[Link] = name