Python tutorial 16: An Informative Guide To Python Slice Operator by Manish Sharma
Skills:
Python for Data80%
Key Takeaways
Using Python Slice Operator to reverse a string
Full Transcript
what is the easiest way possible to reverse a string in Python that's it the easiest way to reverse a string in Python period if you are here to learn how to reverse a string I just showed you thank you so much we'll see you in the next tutorial if you are still here then you are few of those who want to understand the concept to nail the interview so without wasting much of your time let's start the tutorial possibly net i am manish from rebellionrider.com and today in this tutorial we will learn the concepts of Python slice operator yeah the one which we just used to reverse the Python string but before we start learning I just want to ask you to help me in reaching 100k subscribers this year by subscribing to my youtube channel if you haven't already also please don't leave without pressing that thumbs up button thank you so let's start to understand the concept of Python slice operator we first need to understand the indexing there are two types of indexing in Python the first one is simple positional indexing let's see what it is I assume you already know about Python strings if not then watch my python tutorial 7 anyways our string is a one-dimensional array of character the Python interpreter saves all the characters of the string in a sequential manner and assigns them index numbers the index numbers start with 0 which means the first character of the string will be saved at index 0 and the second character will be saved at index 1 and so on this is a very common information but did you know that Python interpreter not only assigns positive index numbers to the string but also assigns negative index numbers which is highly unlikely in other programming languages I bet you did not know that go ahead and comment I else if you knew this already let's come back to our negative indexes the negative index number starts with minus 1 and the numbering starts from the end of the string which means the last character of the string will get index number minus and so on this process of sequential indexing of the strain whether it's positive or negative is called simple positional indexing the second type of indexing is slicing slicing is a process of extracting a substring from the main string in just one single step yes you heard it right you can extract a range of indexes by just writing a single line of code there is no need to write any conditional control or loop statement right in front of you is the syntax of the slice operator this operator has three flags start stop and steps firstly all these three flags are integer Flags which means they accept only integer values secondly all of these are optional first flag starts indicates the index number from where the slicing will start second flag stop indicates the index number where the slicing will stop and a third flag step indicates the number of hops interpreter will take to slice the string let's do some examples and try to understand the Python slice operator I will do multiple examples to show you the use of each of the flag of the Python slice operator for the demonstration we will use our favorite string what's up Internet here I created a variable and named it STR furthermore I stored our favorite string was up Internet into it in the first example we will see the use of the first flag of the Python slice operator let's see I don't want to print this entire string rather I just want to display only the world Internet let's see if we can do that here's of what I have done I have put this slice operator right after this string in the same line where I have declared and initialized our variable in that slice operator I have specified only one value which is ten ten is the index number from where the word internet is starting I have countered that already if you want you can do that too if you will see you will find out that right after the value 10 have put two columns in the Pythian slice operator we use columns to separate the values of the flags from each other there are no values right after those columns which shows that the programmer has not specified the values for the second and the third flag which are stop and stabs respectively when you do not specify the values for any of these flags the interpreter will use their default values the default value for the second flag stop is the last index of the string and for the third flight steps is 1 before I execute and show you the result I just want to mention one more thing never forget to include the values of the start stop and steps flags in a square bracket this entire contraption the integer values separated by columns and enclosed inside square brackets is called the slice operator of the Python programming language also I put the slice operator with a variable declaration for a specific reason however I do not recommend doing that this I will explain to you later in the series anyways now to see the result let's add a print statement which will display the string let's execute and see the result as you can see we only got the word internet printed instead of the entire string let's move on to the next example now suppose instead of the entire string I just want to print only the phrase what's up let's see if we can do that this time I'm using first two flags of the operator the start and the stop here I have specified one as the value of the start flag and nine as the value of the stop flag on execution the interpreter will slice the string and print the service string which is starting from index 1 and ending at index 9 let's execute and see whether we get the desired output or not we got the output but the letter W or the world wort is missing that is exactly why I explained the indexing of the sequence in the beginning of the tutorial if you remember I mentioned earlier that the positive indexes of the string start with zero not with one here I have a specified one as I start index which is not the index of the character W if we replace one with zero then we will get the proper output let's do that let's execute here we got the output great now let's move on to the third example in the third example we will explore all the three flags of the Python slice operator let's see I want to select every second character of this entire string for that the code will be on execution the interpreter will print every second character starting from index 0 to index 19 I have done my calculation and 19 is the last index let's execute and check great here we got every second character of the string printed right on our screen starting from the character at index 0 in this operator call I have a specified 0 which is the first index of the string as our starting index and 19 which is the last index of the string as our ending index in addition to that I have also specified 2 as the value for the flag steps all these three indexes combined together tell the interpreter to process the entire string and print every second index from there in such case when you have to process the entire string which is highly unlikely then you can rely on the default behavior of the Python slice operator which means that to Python slice operator calls which you are seeing right now on your screen are equivalent and produce the same result why don't you go ahead and try it your serve just write this code and try to execute that's it for today Stadium as in the next tutorial I will tell you why I put the Python slice operator in the same line where I declare an angela is the variable there we will also unfold the mystery behind the changing behavior of slice operator on using negative positional indexes but for now I want you to hit the thumbs up button and like the video also subscribe to my channel thanks for watching we'll see you soon this is manish from rebellionrider.com
Original Description
In this Python Tutorial, you will Learn how to reverse a string with just a single line of code using Python Slice Operator by Manish Sharma
------------------------------------------------------------------------
►►►LINKS◄◄◄
Blog: http://www.rebellionrider.com/the-most-innovative-ways-to-utilize-python-slice/
Previous Tutorial
►
-------------------------------------------------------------------------
►Make sure you SUBSCRIBE and be the 1st one to see my videos!
-------------------------------------------------------------------------
►►►Find me on Social Media◄◄◄
Follow What I am up to as it happens on
https://www.facebook.com/TheRebellionRider/
https://twitter.com/rebellionrider
http://instagram.com/rebellionrider
https://plus.google.com/+Rebellionrider
http://in.linkedin.com/in/mannbhardwaj/
You can also Email me at
for E-mail address please check the About section
Please please LIKE and SHARE my videos it makes me happy.
Thanks for liking, commenting, sharing and watching more of our videos
This is Manish from RebellionRider.com
♥ I LOVE ALL MY VIEWERS AND SUBSCRIBERS
#PythonWithRebellionRider #Python3 #PythonIn2019
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Manish Sharma · Manish Sharma · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Oracle Database tutorials 1: How to install Oracle Database 11g on windows 7
Manish Sharma
Oracle Database tutorials 2:How To install SQL Developer on windows 7
Manish Sharma
Oracle Database tutorials 3:How to enable Line numbers in SQL Developer.
Manish Sharma
Oracle Database tutorials 4: database connectivity using SQL developer and command prompt
Manish Sharma
Oracle Database tutorials 5: how to Fetch Data using SELECT - SQL statement by Manish Sharma
Manish Sharma
Oracle Database11g tutorials 6 | | How to use Concatenation operator, character String
Manish Sharma
Oracle Database11g tutorials 7 | |SQL DISTINCT keyword || SQL tutorials
Manish Sharma
Canon EOS 600D 2 lens kit/Canon rebell EOS T3i 2 lens kit Unboxing
Manish Sharma
First look: ORACLE CERTIFIED ASSOCIATE (OCA) CERTIFICATE - ORACLE DATABASE ADMINISTRATOR
Manish Sharma
Oracle Database11g tutorials 8 || SQL DISTINCT with multiple columns |SQL Distinct with Two columns
Manish Sharma
Oracle Database11g tutorials 9 || What is archive log mode and how to enable archive log mode
Manish Sharma
Oracle Database11g tutorials 10 || SQL Single Row Function (SQL Functions )
Manish Sharma
Oracle Database11g tutorials 11: SQL case manipulation function in Oracle Database
Manish Sharma
how to add channel trailer and section on your youtube channel 2014
Manish Sharma
Oracle Database11g tutorials 12 || SQL Concat Function - SQL character manipulation function
Manish Sharma
Oracle Database11g tutorials 13 || SQL substr function / SQL substring function
Manish Sharma
Oracle Database11g tutorials 14 : How to CREATE TABLE using sql developer and command prompt
Manish Sharma
SQL tutorials 15 || How To CREATE TABLE using enterprise manager 11g
Manish Sharma
Oracle Database11g tutorials 16: How to uninstall oracle 11g from windows 7 64 bit
Manish Sharma
ORACLE CERTIFIED PROFESSIONAL(OCP) CERTIFICATE First look - ORACLE DATABASE ADMINISTRATOR
Manish Sharma
Plantronics audio 655 USB headset with Mic Unboxing and Review and Plantronics audio 655 Mic test
Manish Sharma
SQL tutorials 17: SQL Primary Key constraint, Drop primary Key
Manish Sharma
SQL tutorials 18: SQL Foreign Key Constraint By Manish Sharma
Manish Sharma
SQL tutorial 19: ON DELETE SET NULL clause of Foreign Key By Manish Sharma (RebellionRider)
Manish Sharma
SQL tutorials 20: On Delete Cascade Foreign Key By Manish Sharma (RebellionRider)
Manish Sharma
SQL tutorial 21: How To Rename Table in SQL using ALTER TABLE statement By Manish Sharma
Manish Sharma
SQL tutorial 22: How to Add / Delete column from an existing table using alter table
Manish Sharma
SQL tutorial 23: Rename and Modify Column Using Alter Table By Manish Sharma (RebellionRider)
Manish Sharma
SQL tutorial 24 :SQLJoins- Natural Join With ON and USING clause By Manish/Rebellionrider
Manish Sharma
Oracle Database11g tutorials 25: How to install Oracle Database 11g Express Edition R2 on Windows 7
Manish Sharma
SQL tutorial 26: Introduction to SQL Joins in Oracle Database
Manish Sharma
Vidcon 2014 YouTube Fan Funding: How to enable fan funding on YouTube Channel
Manish Sharma
SQL tutorial 27: Right Outer Join in SQL by Manish Sharma for RebellionRider
Manish Sharma
SQL tutorial 28: Left Outer Join By Manish Sharma / RebellionRider
Manish Sharma
SQL tutorial 29: Full Outer Join with example By Manish Sharma/ RebellionRider
Manish Sharma
SQL tutorial 30: Inner Join In SQL by Manish Sharma/RebellionRider
Manish Sharma
SQL tutorial 31 : SQL Cross Join In Oracle Database By Manish Sharma from RebellionRider
Manish Sharma
SQL tutorial 32: How To Insert Data into a Table Using SQL Developer
Manish Sharma
SQL tutorial 33:How To Insert Data into a Table Using SQL INSERT INTO dml statement
Manish Sharma
SQL tutorial 34: How to copy /Insert data into a table from another table using INSERT INTO SELECT
Manish Sharma
SQL tutorial 35: DELETE and TRUNCATE how to delete data from a table
Manish Sharma
SQL tutorial 36: how to create database using database configuration assistant DBCA
Manish Sharma
SQL tutorial 37: How to create NEW USER account using Create User statement in Oracle database
Manish Sharma
SQL tutorial 38: How to create user using SQL Developer in Oracle database
Manish Sharma
SQL tutorial 39: How to create user in oracle using Enterprise Manager
Manish Sharma
SQL tutorial 40: DBA Trick, How to drop a user when it is connected to the database
Manish Sharma
Motorola Moto G 2nd Generation / G2 Unboxing and Review
Manish Sharma
SQL tutorial 41: How to UNLOCK USER in oracle Database
Manish Sharma
SQL tutorial 42: How to Unlock user using SQL Developer By Manish Sharma RebellionRider
Manish Sharma
SQL tutorial 43: How to create an EXTERNAL USER in oracle database By Manish Sharma RebellionRider
Manish Sharma
SQL tutorial 44: How to import data from Microsoft Excel to Oracle Database using SQL Developer
Manish Sharma
SQL tutorial 45: Introduction to user Privileges in Oracle Database By Manish Sharma RebellionRider
Manish Sharma
SQL tutorial 46: What are System Privileges & How To Grant them using Data Control Language
Manish Sharma
SQL tutorial 47: How to Grant Object Privileges With Grant Option in Oracle Database
Manish Sharma
SQL tutorial 48: How to create Roles in Oracle Database
Manish Sharma
SQL tutorial 49: CASE - Simple Case Expression in Oracle Database (1/2)
Manish Sharma
SQL tutorial 50: CASE - Searched Case Expression In Oracle (2/2)
Manish Sharma
SQL tutorial 51: DECODE function in Oracle Database By Manish Sharma (RebellionRider)
Manish Sharma
Oracle Database Tutorial 52 : Data Pump expdp - How to Export full database using expdp
Manish Sharma
Oracle Database Tutorial 53 : Data pump expdp - How to Export tablespace in Oracle Database
Manish Sharma
More on: Python for Data
View skill →
🎓
Tutor Explanation
DeepCamp AI