Write a Python program to format a specified string and limit the length of a string.

Write a Python program to format a specified string and limit the length of a string.

1
2
3
4
5
str_num = "1234567890"
print("Original string:",str_num)
print('%.6s' % str_num)
print('%.9s' % str_num)
print('%.10s' % str_num)

Final output

Leave a Comment