Working with Strings: Upper, Lower, and Title Methods
Strings in Python are sequences of characters that can be modified using
various methods such as `upper()`, `lower()`, and `title()` to change the
case of the string.
- **upper()**: Converts all characters in a string to uppercase.
- **lower()**: Converts all characters in a string to lowercase.
- **title()**: Capitalizes the first letter of each word in a string.
**Example:**
```python
name = "Hi, I'm Mohit"
print(name.upper()) # OUTPUT: HI, I'M MOHIT
print(name.lower()) # OUTPUT: hi, i'm mohit
print(name.title()) # OUTPUT: Hi, I'm Mohit
```
Creating Interactive Programs with User Input
You can use the `input()` function to receive input from users in
interactive programs.
Organizing Code with Functions and Reusability
Functions in Python are reusable blocks of code that help in organizing
and structuring programs. They are defined using the `def` keyword.
**Example:**
```python
def greet():
print("Hello, welcome to Python programming!")
greet()
```
Function Parameters and Arguments in Python
1
, Functions can take inputs, known as *parameters*, and use the values
passed to them, called *arguments*, for processing.
**Example:**
```python
def greet(name):
print(f"Hello, {name}!")
greet("Mohit")
```
Lists in Python: Indexing and Slicing
A **list** in Python is an ordered collection of values. Each item in a list
has an index starting at 0, and lists support slicing to extract portions.
**Example:**
```python
numbers = [1, 2, 3, 4, 5]
print(numbers[0]) # OUTPUT: 1
print(numbers[1:3]) # OUTPUT: [2, 3]
```
Defining and Calling Functions in Python
Functions are defined using the `def` keyword and called by their name,
passing any required parameters in parentheses.
**Example:**
```python
def add_numbers(a, b):
return a + b
result = add_numbers(2, 3)
print(result) # OUTPUT: 5
```
Conditional Statements in Python: If, Elif, and Else Statements
2