Get startedGet started for free

Combining data types

Different types of data types have different properties. For example, strings and floats cannot be mathematically combined. To convert a variable x to an integer, you can use the command int(x). Similarly, to convert a variable y to a string, you can use the command str(y).

It's time for you to change some data types to complete and print a statement.

The variables company_1, year_1, and revenue_1 are available in your workspace.

This exercise is part of the course

Introduction to Python for Finance

View Course

Exercise instructions

  • Convert the data type of variables year_1, and revenue_1 to string.
  • Use these new variables to create and print the following sentence: "The revenue of Apple in 2017 was $229.23 billion."

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Update data types
year_1_str = ____(year_1)
revenue_1_str = ____

# Create a complete sentence combining only the string data types
sentence = 'The revenue of ' + company_1 + ' in ' + ____ + ' was $' + ____ + ' billion.'

# Print sentence
print(sentence)
Edit and Run Code