Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Trees

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,772 questions

12,146 answers

573 users

How to get a slice of a string in Python

1 Answer

0 votes
s = "python java c++ php, c, c# javascript, vb"

n = 2
print("1:", s[n])
print("2:", s[n:n + 1])
print("3:", s[n:n + 2])
print("4:", s[n:n + 3])
print("5(a):", s[n:n + 4])
print("5(b):", s[n:n + 4:2])
print("6(a):", s[n:n + 7])
print("6(b):", s[n:n + 7:2])
print("6(c):", s[n:n + 7:3])

s = "pythonWjava c++ php, c, c# javascript, vb"
print("6(a):", s[n:n + 7])
print("6(b):", s[n:n + 7:2])
print("6(c):", s[n:n + 7:3])


'''
run:

1: t
2: t
3: th
4: tho
5(a): thon
5(b): to
6(a): thon ja
6(b): to a
6(c): tna
6(a): thonWja
6(b): toWa
6(c): tna

'''

 




answered Sep 16 by avibootz
...