Invalid Literal for Int with Base 10 – Python Error

Ever got this python error? invalid literal for int with base 10 Or some sort of this same message? Keep reading to know the solution for this Python error and to master the data types conversions.

Python Error: Invalid Literal for Int with Base 10

In this post, I will explain the solution for the “invalid literal for int” errors on Python. We all know that with python is very handy when converting between different data types easily. From strings to integers, from integers to floats, passing a string to float…

But, what if you want to convert from a string representing a float to an integer?

Well, then python will raise an error saying it can’t! See the example below:

# String with some numbers (float)
strval = "152.569"
intval = int(strval) 
# Output: Traceback (most recent call last):
  File "", line 3, in <module>
	intval = int(strval)
ValueError: invalid literal for int() with base 10: '152.569'

Read more

Python Remove Element from List – pop() and remove()

In this post, I will show you how to remove an element from a list in python. The main function to use is the built-in remove() functionality, del() and pop().

List Remove() Function in Python

The remove() function is as easy as it sounds:


The syntax, as you can see, is very easy: we just need to pass the item we want to remove from the list.

The parameter of the remove() function is only the item value in the list:

  • The remove() only takes one item as parameter, the name of the item, and removes it from the list
  • The function will return an error of “ValueError: list.remove(x): x not in list ” if the item is not found in the list.

The remove() function, similarly to other functionalities in python, does not give back any value (it is a method, rather than an actual function).

Read more

How to Git Delete Branch Remote (and locally)

If you use Git as your version control server, it is very probable that you need to delete a remote branch. In this post, I will show you how to delete a branch locally and remotely.

Display local and remote git branches

To delete a local branch, first, we will need to print and display all our branches. We can get that using the command git branch -a, the argument -a. This command will display all available branches in the server:

git branch -a
# This will print our branches as:
# *master
#   testbranch
#   remote/rbranch/master
#   remote/rbranch/testbranch

In the case I showed you above, we have a local branch testbranch and two other remote branches.

Read more

Convert a Byte to String in Python (or vice-versa)

To convert a byte to string in python is pretty easy and straight forward, but it is very important to understand the differences between these two data types (scroll down to the examples to see the code directly).

Converting Bytes to String (Theory)

In python, a byte object is a series of bytes. The python byte object is what our machines (computing machines), can read and what can store (or write).

A String, contrarily to bytes, is an encoded form of bytes that is able to be stored in our machines. This encoding makes us, humans, able to read this representation of bytes in a readable manner.

Encoding of a byte can be done in several ways, the most used ones (and most common) are the ASCII and UTF-8 encoding modes. In Python 3, the default encoding method is UTF-8.

To make it simpler, here is a very simple diagram:

Simple diagram relation between bytes and strings in Python

Read more