From the course: Python for JavaScript Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Python slices

Python slices - Python Tutorial

From the course: Python for JavaScript Developers

Start my 1-month free trial

Python slices

- [Instructor] Slices allow us to quickly manipulate strings and collections. Gaining familiarity with them may save us quite a bit of time. Moreover, it keeps our code more clean and concise. So here I am in 02_05.js just to have a starting point and look at a JavaScript slice. So on line one, I define an array of three ages, basically three numbers. And on line three, I grab those last two numbers, using the slice method. Then on line four, I console.log this. So let's just run this code. So here I am in my terminal and I'm going to run this using node since this is JavaScript. CH_02_05.js. And I get the last two items. So let's clear my terminal. So let's have a look at some Python slices. So here I am at 02_05.py and functionality of slicing is very similar in Python. Syntax, however, is a bit different. So here on line one, I define a list of four items called AGES and on line two, I just grab the…

Contents