Strings (Python)

Strings

> Tutorial

Strings

Character strings are a type of value used to represent text.

A string is written between single or double quotes:

String operations

The + operator is the concatenation operator, which "glues" two strings together:

Careful: in Python, you can't directly concatenate a string and a number. You need to convert the number to a string with str(): "life: " + str(me.life).

Many operations are available on strings. The main ones are:

Examples:

Greet your opponent

The enemy.name property returns the name of an entity. We'll use it to greet our opponent on turn 1:

The me.say() method makes your leek say something; it costs 1 TP . Against an enemy named Domingo, our leek will say: "Hi Domingo!". Feel free to customize it, as long as you stay polite!

❓ Quiz

What is the result of the code "10" + str(5) + "aa"?

"105aa" "15aa" "10aaaaaaaa" "15aaaaa"

What is the result of the code "eucalyptus"[4:7]?

"lyp" "euc" "ptus" "euca"

Full AI