“Python plasterka sznurka” Kod odpowiedzi

Krojenie sznurka Pythona

my_string = "Hey, This is a sample text"
print(my_string[2:]) #prints y, This is a sample text
print(my_string[2:7]) #prints y, Th excluding the last index
print(my_string[2::2]) #prints y hsi  apetx
print(my_string[::-1]) #reverses the string => txet elpmas a si sihT ,yeH
Worried Wallaby

Krojenie sznurka Pythona

Concept:
s[x:y:z] , x- left index , y-1 - right index 
z is the number of steps of jumping between 2 chr 
if z>0 :
    direction of jump is right to left(R2L)
else:
    direction of jump is left to right(L2R)
s[:3] means x=0,y=2,z=1
s[3:] means x=3,y=len(s)-1,z=1

examples:

s="dbdhdhndnbdd"
print(s[2:6:2])
//prints dd as left index is 2 right is 5 -> substring is dhdh & 2 means d,skip h,then d
s="djdjcjfd"
print(s[::-2])
//prints djjj, left index is 0 ,right is len(s)-1 -> substring is djdjcjfd & 
//-2 means start from right side in substring in steps of 2-> d,skip f,then j,skip c,then j & j
ap_Cooperative_dev

Python plasterka sznurka

# Python program to demonstrate
# string slicing
  
# String slicing 
String ='ASTRING'
  
# Using indexing sequence
print(String[:3])
print(String[1:5:2])
print(String[-1:-12:-2])
  
# Prints string in reverse 
print("\nReverse String")
print(String[::-1])

#AST
#SR
#GITA

#Reverse String
#GNIRTSA
David Cao

Krojenie strun w Pythonie

>>> x = "Follow us on Softhunt.net"
>>> x[0:6]
'Follow'
>>> x[-18:-4]
'us on Softhunt'
Outrageous Ostrich

Jak pokroić sznur w Python

b = "Hello, World!"
print(b[-5:-2])

#Output: orl
Asif Iqbal Paracha

Odpowiedzi podobne do “Python plasterka sznurka”

Pytania podobne do “Python plasterka sznurka”

Więcej pokrewnych odpowiedzi na “Python plasterka sznurka” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu