String
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 6 of 92.
A string is a piece of text: a sequence of characters such as letters, digits, spaces and symbols. In GDScript its type is String, with a capital S.
To create a string, put the text inside double quotes or single quotes:
var s1 = "This is a string"
var s2 = 'This is also a string'The quotes mark where the text starts and ends. They are not part of the value, so print(s1) shows This is a string.
Single quotes are handy when the text itself contains double quotes:
var line = 'She said "Hi!"'
print(line)This prints She said "Hi!".
GDScript has no separate type for a single character: "A" is a String that is one character long.
Digits inside quotes are text too. "25" is a String, while 25 is an int.
Challenge
BeginnerStore the string I am learning to code with Coddy! in a variable named coddy.
Write the exact text, with the same capital letters, spaces and !. Do not change the print() line. It prints:
coddy = "I am learning to code with Coddy!"Try it yourself
extends Node
func _ready():
# Create the variable coddy below
# Don't change the line below
print('coddy = "', coddy, '"')
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary OperatorPractice on your own: Online GDScript compiler