ICT Notes
ICT Notes
1. Relational Operator:
- Used to compare values.
- Returns either True or False depending on the condition.
2. Conditional `If`:
- Tests a condition. If true, the code block inside `if` is executed.
- Syntax:
```python
if condition:
# statements
```
3. Conditional `If-Else`:
- Executes code inside `if` if the condition is true, otherwise runs code inside
`else`.
- Example:
```python
a = 10
b = 20
if a > b:
print("a is greater")
else:
print("b is greater")
```
4. `Elif` Statement:
- Checks multiple conditions. If `if` is false, `elif` is checked, and so on.
- Syntax:
```python
if condition:
# statements
elif condition:
# statements
else:
# statements
```
6. `input()` Function:
- Used to get user input.
- Example:
```python
name = input("Please Enter Your Name: ")
print("Name:", name)
```
7. Python List:
- A collection of ordered, changeable elements.
- Allows duplicate values.
- Can contain items of different data types.
- Syntax: `[item1, item2, ...]`
8. List Operations:
- Accessing elements: Use the index (starts at 0).
``` python
list1 = ['apple', 'banana', 'cherry']
print(list1[0]) # Outputs: apple
```
- Adding elements:
```python
list1.append("orange")
list1.insert(1, "grape")
```
- Deleting elements:
```python
list1.remove("banana")
list1.pop(1) # Removes item at index 1
list1.pop() # Removes last item
```
---