I need to intake a number like: 200939915
After doing this, which I know how, I need to remove the first number so it becomes: 00939915
What is the best way to do this?
To delete nth digit from starting:Get the number and the nth digit to be deleted. Count the number of digits. Loop number of digits time by counting it with a variable i. If the i is equal to (number of digits – n), then skip, else add the ith digit as [ new_number = (new_number * 10) + ith_digit ].
Note that Python integers are immutable, so the only way to remove a digit from an integer is to create a new integer that doesn't contain the digit. An alternative approach is to use string slicing. To remove the last digit from an integer: Use the str() class to convert the integer to a string.
Use string slicing to remove first characters from a string Use string slicing syntax string[n:] with n as the amount of characters to remove the first n characters from a string.
char *c = "200939915";
char *d = c + 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With