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

Kursinhalt

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

book
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.

Aufgabe

Swipe to start coding

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. Convert numbers to the str data type to manage the task.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 5
toggle bottom row

book
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.

Aufgabe

Swipe to start coding

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. Convert numbers to the str data type to manage the task.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 5
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
We're sorry to hear that something went wrong. What happened?
some-alt