User FAQs


1) Why are strings immutable ?



2) How can you return a range of characters of a string?
You can return a range of characters by using the "slice syntax".
Specify the start index and the end index, separated by a colon, to return a part of the string, for example:
Get the characters from position 2 to position 5 (not included):

b = "Hello, World!" 
print(b[2:5])

3) How can you check if all the characters in a string are alphanumeric?
You can use the isalnum() method, which returns True if all the characters are alphanumeric, meaning alphabet letter (a-z) and numbers (0-9).


4) How do I convert a string to a number ?
For integers use the built-in int() type constructor
For floating points use the built-in float() type constructor
Do not use eval()

int ('1') == 1  
float('1') = 1

The number by default are interpreted as a decimal and if it is represented by int('0x1') then it gives an error as ValueError
In this the int(string,base) the function takes the parameter to convert string to number in this the process will be like int('0x1',16) == 16


5) How do I modify a string in python?
You can't because strings are immutable in python.
In most situations, you should simply construct a new string from the various parts you want to assemble it from.
Work with them as lists; turn them into strings only when needed.

>>> s = list("Hello zorld") 
>>> s
['H', 'e', 'l', 'l', 'o', ' ', 'z', 'o', 'r', 'l', 'd']
>>> s[6] = 'W'
>>> s
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
>>> "".join(s)
'Hello World'

6) How can you convert a string to an integer?
You can use the int() function, like this:

num = "5" 
convert = int(num)

7) What is docstring ?
This is a documentation string that is a multi-line string used to document a code segment.
It should describe what the function or method does.




© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext