0Pricing
Python Academy · Lesson

Strings and Type Conversion

Work with string values and convert between different data types.

Strings and Type Conversion is a free Python Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Introduction

Strings in Python are immutable sequences of Unicode characters, created with single or double quotes. Type conversion lets you switch between types.

Creating Strings

Use single quotes, double quotes, or triple quotes for multi-line strings. All create the same str type.
s = 'hello'
t = "world"
ml = '''line1
line2'''

String Immutability

You cannot change a character in place. s[0] = 'H' raises TypeError. Instead, create a new string: s = 'H' + s[1:].

int() Conversion

int('42') converts a string to integer. int(3.9) truncates to 3. Passing a non-numeric string raises ValueError.
print(int('42'))
print(int(3.9))

float() Conversion

float('3.14') converts a string to float. float(7) gives 7.0. Useful when reading numeric input from users.
print(float('3.14'))
print(float(7))

str() Conversion

str(100) gives '100'. str(True) gives 'True'. Use str() to concatenate numbers into strings without TypeError.
age = 25
print('Age: ' + str(age))

bool() Conversion

bool(0) is False. bool(1) is True. bool('') is False. bool('hi') is True. Useful for truthiness checks.
print(bool(0))
print(bool('hello'))

Type Checking with isinstance()

isinstance(x, int) returns True if x is an int. Prefer isinstance() over type() == int for subclass-safe checks.
print(isinstance(42, int))
print(isinstance(3.14, float))

Implicit Type Coercion

Python does NOT silently coerce types like JavaScript. '3' + 3 raises TypeError. Be explicit with conversions.
# This raises TypeError:
# print('3' + 3)

ord() and chr()

ord('A') gives 65 (Unicode code point). chr(65) gives 'A'. Useful for character arithmetic.
print(ord('A'))
print(chr(65))

Conversion Errors

Always wrap conversions in try/except when the source is user input. int('abc') raises ValueError at runtime.

Quick Check

What does int(3.9) return in Python?

Recap

Python strings are immutable Unicode sequences. Convert between types using int(), float(), str(), bool(). Always handle ValueError when converting user input.

Keep Going

Great work! Move on to the next lesson to continue building your skills.

Frequently asked questions

Is the “Strings and Type Conversion” lesson free?

Yes — the full text of “Strings and Type Conversion” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.

What will I learn in “Strings and Type Conversion”?

Work with string values and convert between different data types. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Strings and Type Conversion” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Variables and Assignment
  2. Numeric and Boolean Types
  3. Strings and Type Conversion
  4. Reading User Input
← Back to Python Academy