fb pixel

Different types in a list

Some programming languages don’t allow having different types of variables (like integers and strings) in a single list. Yet, Python is very flexible and allows having several types in a single list:
different = [

print(type(different[0]), type(different[1]), type(different[2]))
# <class 'str'> <class 'int'> <class 'float'>
In this code snippet, the first 3 elements of the different list are string, int, and float.
Lists can contain other types like boolean values, floating-point values, and even other lists (nested lists).


Define a list of 8 values that are read from the input. The even indices would be integers (starting from 0) and the odd ones will be strings.
The output of the program should contain the sum of the numbers on the first line and the strings separated by a space on the second line.
10 first 20 second 7 third -3 hello
34 first second third hello
Hint: Writing the output with an f-string might be very convenient.
To check your solution you need to sign in
Sign in to continue