Courses/Python Programming/Data Types and Type Conversion

Data Types and Type Conversion

Understand Python data types

Beginner⏱️ 12 minutes

Lesson Content

Python Data Types

Main Types:

text = "Hello"          # str (string)
number = 42             # int (integer)
decimal = 3.14          # float
is_true = True          # bool (boolean)
items = [1, 2, 3]       # list

Type Conversion:

str(42)        # "42" (number to string)
int("42")      # 42 (string to number)
float("3.14")  # 3.14 (string to float)

Check Type:

type(42)       # <class 'int'>

Task: Convert string "123" to integer, add 77 to it, and print the result.

python
Loading...
Expected Output: 200
Previous
Python Basics - Print and Variables
Next (Complete this lesson first)
Lists - Python Arrays