Here how can i split the string into sub string like follows:
If my string is 'python'
then it need to store like a1=py, a2=th, a3=on
.
But the input will get by input() function. How can do it?
Here how can i split the string into sub string like follows:
If my string is 'python'
then it need to store like a1=py, a2=th, a3=on
.
But the input will get by input() function. How can do it?
s='python'
a1,a2,a3=[s[i:i+2] for i in range(0,len(s),2)]
print(a1,a2,a3)
Output
py th on
If you need to use input and variable split length
s=input('Enter String: ')
n=2
a1,a2,a3=[s[i:i+2] for i in range(0,len(s),n)]
print(a1,a2,a3)
Output
Enter String: python
py th on
Try this one:
If you want to get 2
length substring from given string.
In [114]: a
Out[114]: 'python'
In [115]: [a[i:i+2] for i in range(0, len(a), 2)]
Out[115]: ['py', 'th', 'on']
You can make 2
a variable, depending on which length substring you want.