Python TutorialLesson 10Free preview
Python Casting
This lesson is part of Python · All levels
Summary
Casting is the process of converting values from one dataset type to another, for example from a string to a number. Python provides the functions int(), float(), and str() for those needs, including when processing data from user input. A failed conversion will cause an error, so it's best to check the value first.
Key points
- Int() converts the value to an integer.
- Float() converts the value to a decimal number.
- Str() converts the value into text.
- The input from the user is always a string so it needs to be converted when it's to be counted.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.