“substrat en python” Réponses codées

sous-chaîne python

# string [start:end:step]
string = "freeCodeCamp"
print(string[0:len(string)-1])		# freeCodeCam
print(string[0:5])		            # freeC
print(string[2:6])		            # eeCo
print(string[-1])		            # p
print(string[-5:])		            # eCamp
print(string[1:-4])                 # reeCode
print(string[-5:-2])	            # eCa
print(string[::2])		            # feCdCm
VasteMonde

substrat en python

public class Substring {
 
  public static void main(String[] args) {
    //consider this string
    //here indexing starts from 0 and space is considered as char in string
    String s = "Welcome to Scaler"
 
    //1
    System.out.println("The substring is: " + str.substring(11));
 
    //2
    System.out.println("The substring is: " + str.substring(0, 7));
  }
}
Disgusted Dolphin

substrat en python

public class Substring {
 
  public static void main(String[] args) {
    String s = "Scaler is part of Interviewbit";
    System.out.println(”Hey” + s.str.substring(0, 0));
 
  }
}
Disgusted Dolphin

Sous-lames possibles d'une chaîne Python

# Python3 code to demonstrate working of
# Get all substrings of string
# Using list comprehension + string slicing
  
# initializing string 
test_str = "Geeks"
  
# printing original string 
print("The original string is : " + str(test_str))
  
# Get all substrings of string
# Using list comprehension + string slicing
res = [test_str[i: j] for i in range(len(test_str))
          for j in range(i + 1, len(test_str) + 1)]
  
# printing result 
print("All substrings of string are : " + str(res))
Super Snake

compter le substrat dans la chaîne python

def count_substring(string,sub_string):
    l=len(sub_string)
    count=0
    for i in range(len(string)-len(sub_string)+1):
        if(string[i:i+len(sub_string)] == sub_string ):      
            count+=1
    return count  
Repulsive Ratel

Réponses similaires à “substrat en python”

Questions similaires à “substrat en python”

Plus de réponses similaires à “substrat en python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code