Q:

python length

# Python program to demonstrate the use of 
# len() method   
  
# Length of below string is 5 
string = "geeks" 
print(len(string)) 
  
# Length of below string is 15 
string = "geeks for geeks" 
print(len(string)) 
7
string = "test"
print(len(string))
#>>> Output "4"
1
string = "hello"
print(len(string))
#>>> Outputs "5"
if len(string) >= 10:
  print("This string is grater then 10")

if len(string) <= 10:
  print("This string is smaller then 10")
 
# Outputs "This string is smaller then 10"
6
len(var)
len() is a built-in function in python. You can use the len() to get the length of the given string, array, list, tuple, dictionary, etc. Value: the given value you want the length of. Return value a return an integer value i.e. the length of the given string, or array, or list, or collections.
1
# Python program to demonstrate the use of 
# len() method   
  
# Length of below string is 5 
string = "geeks" 
print(len(string)) 
  
# Length of below string is 15 
string = "geeks for geeks" 
print(len(string)) 
5
def lcs(X, Y):
  
    n = len(Y)
    m = len(X)
    
    L = [[None]*(n + 1) for i in range(m + 1)]
    for i in range(m + 1): 
        for j in range(n + 1): 
            if i == 0 or j == 0 : 
                L[i][j] = 0
            elif X[i-1] == Y[j-1]: 
                L[i][j] = L[i-1][j-1]+1
            else: 
                L[i][j] = max(L[i-1][j], L[i][j-1])
                
    return L[m][n] 
0
To get the length of a string, use the len() function.
3
# to get the length of a string or array, use the len() method
my_string = "Hello World"
my_list = ["apple", "banana", "orange"]

print(len(my_string)) # outputs 11
print(len(my_list)) # outputs 3
2
# Python program to demonstrate the use of 
# len() method   

string = "Trinix" 
print(len(string)) # 6 
0

New to Communities?

Join the community