HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Python: Print and RepeatVariablesData Types & NumbersStringsListsConditions (if / elif / else)Loops (for / while)FunctionsOperatorsDictionariesTuples & SetsError Handling (try / except)Classes (Object-Oriented)File OperationsComments & IndentationBooleans (True / False)Lambda & map / filterModules (import)InheritanceVariable Scope
REFERENCE
📖 Overview
🖥️ Output & Input
🔢 Numbers & Math
✍️ String
len()upper() / lower()strip()replace()split()join()find() / incount()
📋 List
🗂️ Dictionary & Set
🔁 Condition & Loop
🧩 Function
📁 File & Error
🔄 Type & Conversion
Python›REFERENCE›String
✍️

String

Methods for changing, searching, splitting and formatting strings.

CommandDescription
len()Returns the number of characters (or elements).
upper() / lower()Converts text to upper / lowercase.
strip()Removes leading and trailing whitespace.
replace()Replaces a substring with another string.
split()Splits a string into pieces and makes a list.
join()Joins list elements into a single string.
find() / inFinds whether/where a piece is in the text.
count()Counts how many times a piece occurs.

len()

Try it yourself →

Returns the number of characters (or elements).

Syntax

len(text)

Description

Returns how many characters a string has, or how many elements a list has.

Returns

The length (int).

Example

print(len("merhaba"))
print(len([1, 2, 3, 4]))

Expected output

7
4

When to use?

Checks like whether an entered password is long enough, or whether a list is empty.

upper() / lower()

Try it yourself →

Converts text to upper / lowercase.

Syntax

text.upper() · text.lower()

Description

upper() makes all letters UPPERCASE, lower() makes all lowercase. It doesn't change the original, it returns new text.

Returns

Converted new text (str).

Example

print("HexLibrary".upper())
print("HexLibrary".lower())

Expected output

HEXLIBRARY
hexlibrary

When to use?

Ignoring case differences when comparing user input (email, search).

Common mistakes

  • ⚠️ Unexpected results may occur with the Turkish 'i' character (I/İ conversion).

strip()

Try it yourself →

Removes leading and trailing whitespace.

Syntax

text.strip()

Description

Cleans up the whitespace/newline characters at the start and end of a string. If you pass characters in the parentheses, it removes those.

Returns

Cleaned new text.

Example

print("   spacy   ".strip())
print("###title###".strip("#"))

Expected output

spacy
title

When to use?

Cleaning up unwanted whitespace in text coming from a form or file.

replace()

Try it yourself →

Replaces a substring with another string.

Syntax

text.replace(old, new)

Description

Replaces all old parts in the text with new ones. Doesn't break the original, returns new text.

Parameters

oldThe piece being searched for.
newThe piece to put in its place.

Returns

Modified new text.

Example

print("leo max leo".replace("leo", "emma"))

Expected output

emma max emma

When to use?

Cleaning up text, filling placeholders in templates.

split()

Try it yourself →

Splits a string into pieces and makes a list.

Syntax

text.split(separator)

Description

Splits the string at the given separator and returns the pieces as a list. If no separator is given, it splits at whitespace.

Returns

A list made of the pieces.

Example

print("apple,pear,cherry".split(","))
print("one two three".split())

Expected output

['apple', 'pear', 'cherry']
['one', 'two', 'three']

When to use?

Separating a CSV row into fields, splitting a sentence into words.

join()

Try it yourself →

Joins list elements into a single string.

Syntax

separator.join(items)

Description

The opposite of split(). Joins a string array by placing a separator between them. Note: separator first, items inside parentheses.

Returns

The joined string.

Example

print("-".join(["2024", "10", "02"]))
print(" ".join(["code", "learn"]))

Expected output

2024-10-02
code learn

When to use?

Converting list data into a single-line text (date, path, sentence).

Common mistakes

  • ⚠️ If the list contains numbers, first convert them to str(): '-'.join(map(str, numbers)).

find() / in

Try it yourself →

Finds whether/where a piece is in the text.

Syntax

text.find(part) · part in text

Description

find() gives the starting position (index) of the part, or returns -1 if not found. If you are just checking whether it exists, 'part in text' is more readable (True/False).

Returns

The position (int) or True/False.

Example

print("merhaba".find("hab"))
print("cat" in "education")

Expected output

3
True

When to use?

A search box, checking whether a word appears in some text.

count()

Try it yourself →

Counts how many times a piece occurs.

Syntax

text.count(part)

Description

Returns the number of times the given piece repeats in the text (or list).

Returns

The repeat count (int).

Example

print("mississippi".count("s"))

Expected output

4

When to use?

Measuring the frequency of a letter/word, simple text analysis.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code