Python string length

Length of a string represents the number of characters in a string. To know the length of a string, we can use the len() function. This function gives the number of characters including spaces in the string.

string length using len()

CopiedCopy Code

str = 'Core Python' 
n = len(str) 
print(n)

string length using char count

CopiedCopy Code

str = 'Core Python'
count=0
for i in str:
   count+=1
print(count)

Python string length A Python program to access each element of a string in forward and reverse orders using while loop.
CopiedCopy Code

str = 'Core Python' 
n = len(str)
i=0 
while i<n: 
   print(str[i], end='') 
i+=1 
print() 
i=-1 
while i>=-n: 
   print(str[i], end='') 
i-=1 
print() 
i=1 
n = len(str) 
while i<=n: 
   print(str[-i], end='') 
i+=1
A Python program to access the characters of a string using for loop.

CopiedCopy Code

str = 'Core Python' 
for i in str: 
print(i, end='') 
print() 
for i in str[:: -1]: 
print(i, end='')