Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Converting: str() | Bring All the Topics Together
Data Types in Python
course content

Course Content

Data Types in Python

Data Types in Python

1. Getting Familiar With Numbers in Python
2. True or False?
3. Strings
4. Bring All the Topics Together

Converting: str()

Let's talk about strings!

As you remember, the following text leads to an error:

1
print("My age is" + 20)
copy

To implement concatenation here, we can just put 20 in quotes, like "20", but this solution doesn't look beautiful program-wise.

Hence, your work will be more fruitful if we can convert everything into strings. Here, the str() function should be implemented:

1
print("My age is " + str(20))
copy

Note

The syntax of this operation may appear familiar, resembling that of the int() or float() functions. In reality, it is identical, as it involves converting an argument into a string using the str() function.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 4. Chapter 5
toggle bottom row

Converting: str()

Let's talk about strings!

As you remember, the following text leads to an error:

1
print("My age is" + 20)
copy

To implement concatenation here, we can just put 20 in quotes, like "20", but this solution doesn't look beautiful program-wise.

Hence, your work will be more fruitful if we can convert everything into strings. Here, the str() function should be implemented:

1
print("My age is " + str(20))
copy

Note

The syntax of this operation may appear familiar, resembling that of the int() or float() functions. In reality, it is identical, as it involves converting an argument into a string using the str() function.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 4. Chapter 5
toggle bottom row

Converting: str()

Let's talk about strings!

As you remember, the following text leads to an error:

1
print("My age is" + 20)
copy

To implement concatenation here, we can just put 20 in quotes, like "20", but this solution doesn't look beautiful program-wise.

Hence, your work will be more fruitful if we can convert everything into strings. Here, the str() function should be implemented:

1
print("My age is " + str(20))
copy

Note

The syntax of this operation may appear familiar, resembling that of the int() or float() functions. In reality, it is identical, as it involves converting an argument into a string using the str() function.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Let's talk about strings!

As you remember, the following text leads to an error:

1
print("My age is" + 20)
copy

To implement concatenation here, we can just put 20 in quotes, like "20", but this solution doesn't look beautiful program-wise.

Hence, your work will be more fruitful if we can convert everything into strings. Here, the str() function should be implemented:

1
print("My age is " + str(20))
copy

Note

The syntax of this operation may appear familiar, resembling that of the int() or float() functions. In reality, it is identical, as it involves converting an argument into a string using the str() function.

Task

You've already made it through a lot of chapters, way to go!

Your task here is to correct mistakes to make the program execute. The additional highlight of this situation lies in the presence of strings and the inclusion of intriguing pieces of information. 😊

You should receive the following output:

  1. The number of vertices of a pyramid is 5.
  2. The number of Major Arcana cards in the divinatory Tarot is 22.
  3. The largest number that is not the sum of distinct squares is 128.

Convert numbers to the string data type to manage the task.

Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 4. Chapter 5
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt