Skip to content

added more examples for string slicing #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions Lesson 6 - String Manipulation/StringSlicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,41 @@
#OBS: always stops at the previous index(number)


print(word[2:7]) -> #Result: otosy -> #strts from 2 and ends before 7
print(word[2:7]) #Result: otosy -> #strts from 2 and ends before 7

print(word[:5]) -> #Result: photo -> #ends before 5
print(word[:5]) #Result: photo -> #ends before 5

print(word[:]) -> #Result: photosynthesis -> #print whole string
print(word[:]) #Result: photosynthesis -> #print whole string

print(word[::3]) -> #Result: ptyhi -> #print 0 and multiple of 3 afterwards
print(word[::3]) #Result: ptyhi -> #print 0 and multiple of 3 afterwards

print(word[3::3]) -> #Result: tyhi -> #print 3 and multiple of 3 afterwards
print(word[3::3]) #Result: tyhi -> #print 3 and multiple of 3 afterwards

print(word[:-1]) -> #Result: photosynthesi -> #ends before -1
print(word[:-1]) #Result: photosynthesi -> #ends before -1

print(word[:-7]) -> #Result: photosy -> #ends before -7
print(word[:-7]) #Result: photosy -> #ends before -7

print(word[::-1]) -> #Result: sisehtnysotohp -> #print string in reverse
print(word[::-1]) #Result: sisehtnysotohp -> #print string in reverse

print(word[5::-1]) -> #Result: sotohp -> #print reverse till 5
print(word[5::-1]) #Result: sotohp -> #print reverse till 5

# Using slicing with reverse and specific stop:
print(word[8:3:-1]) # Result: tonyt -> Starts from 8 and goes to index 3 (exclusive) in reverse

# Entire string in reverse:
print(word[::-1]) # Result: sisehtnysotohp -> Reverses the whole string

# Reverse from a specific index:
print(word[7::-1]) # Result: ynotohp -> Starts from index 7 and reverses to the beginning

# Reverse from a specific index to a specific index:
print(word[10:4:-1]) # Result: ehtony -> Starts at index 10 and reverses to index 5 (exclusive)

# Extract with a step:
print(word[1:12:2]) # Result: htsyhs -> From index 1 to index 12 (exclusive) with step of 2

# Negative indices with slicing:
print(word[-1:-6:-1]) # Result: siseh -> Starts at the last character and goes back 5 characters

# Reverse specific part:
print(word[6:0:-1]) # Result: ysohto -> Starts at index 6 and reverses to index 1 (exclusive)
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,56 @@
# Learning-Object-Oriented-Python
![](https://www.codetriage.com/josharsh/learning-object-oriented-python/badges/users.svg)
This repository walks you through the Object Oriented Programming in python. Illustrates real world examples, working codes and going about finding a coding solution.


# Learning Object-Oriented Python

This repository walks you through the concepts of **Object-Oriented Programming (OOP)** in Python. It provides real-world examples, practical coding exercises, and solutions to help you master OOP concepts effectively.

---

## Table of Contents

- [Overview](#overview)
- [Features](#features)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Lessons](#lessons)
- [Contributing](#contributing)
- [License](#license)

---

## Overview

This repository is a comprehensive guide to learning Object-Oriented Programming in Python. Whether you're a beginner or someone looking to strengthen your OOP skills, this project has resources for you.

---

## Features

- Detailed lessons covering OOP concepts.
- Practical examples and working code.
- Real-world problem-solving approaches.

---

## Getting Started

### Prerequisites

Before using this repository, ensure you have the following installed:

- Python 3.6 or higher
- A code editor (e.g., VS Code, PyCharm)
- Git (for version control)


## Lessons

Introduction to Python - Basics of Python programming.
Using Functions - Understanding Python functions.
Introduction to OOP Concepts - Core OOP principles.
OOP Implementation - Practical OOP examples.
Web Scraping - Using Python for web scraping.
String Manipulation - Advanced string operations.