Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Concatenation and Basic Strings

Strings + Numbers

All topicsPractise exam questions
Knowledge organiser

Concatenation and Basic Strings

301.5b

Convert before joining.

What you need to know

You cannot concatenate a string and a number directly. Use str() to convert the number first, or use commas in print() which adds spaces automatically.

Key points

  • "Score: " + 10 causes TypeError
  • Fix: "Score: " + str(10)
  • print("Score:", 10) works — commas auto-convert
  • Use str() to cast numbers before concatenating

Code examples

Joining strings and numbers
python
score = 95
print("Score: " + str(score))
print("Score:", score)