This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

I know what this does but what does it actually mean?  RSS feed

 
Ranch Hand
Posts: 163
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys

i know



reverses a string

but what does ::-1 mean?

is it from the start of the whole array
to the end of the whole array
step at -1?

 
wayne brandon
Ranch Hand
Posts: 163
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
myString = "Hello pie!"
reverse = myString[::-1]
print(reverse)

is there another way to do this without a loop?
 
Saloon Keeper
Posts: 2476
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

wayne brandon wrote:what does ::-1 mean?


It is extended slice syntax.  The format is object[start:stop:step] (step is optional).  If you don't specify the start and stop values, the entire object will be sliced.  A negative value for step will cause the slicing to be performed in reverse order.
 
We don't have time for this. We've gotta save the moon! Or check this out:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!