(Cleaned up and updated as part of the full wiki cleanup) (canned edit summary)
(Cleaned up and updated as part of the full wiki cleanup) (canned edit summary)
Line 1: Line 1:
 
{{other version|3.0|2.0|1.4}}
 
{{other version|3.0|2.0|1.4}}
'''Casting''' is the conversion of data types for compatibility within methods. For example, a [[list]] is cast to a [[string]] whenever it is used as a string input. So joining a list [a, b, c] to "... is a list" will return the string "a b c ... is a list".
+
'''Casting''' is the conversion of data types for compatibility within methods. For example, a [[list]] is cast to a [[string]] whenever it is used as a string input. For example, joining a list [a, b, c] to "... is a list" will return the string "a b c ... is a list".
  
 
== Rules ==
 
== Rules ==
Line 64: Line 64:
 
|""
 
|""
 
|0
 
|0
|-
 
 
|
 
|
 
+
|}
 
[[de:Typumwandlung]]
 
[[de:Typumwandlung]]
 
[[Category:Computer Science]]
 
[[Category:Computer Science]]
 
[[ja:キャストの規則]]
 
[[ja:キャストの規則]]

Revision as of 00:50, 19 February 2020

This article or section documents the current version of Scratch (version 3.0). For this article in Scratch 2.0, see Casting (2.0). For this article in Scratch 1.4, see Casting (1.4).

Casting is the conversion of data types for compatibility within methods. For example, a list is cast to a string whenever it is used as a string input. For example, joining a list [a, b, c] to "... is a list" will return the string "a b c ... is a list".

Rules

Casting in Scratch follows the following rules:

Casting Rules String input Number input
Strings String:
"abc"
"abc" 0
String:
"123"
"123" 123
Numbers Number:
123
"123" 123
Booleans Boolean:
true
"true" 1
Boolean:
false
"false" 0
Lists List:
["a", "b", "c"]
"abc" 0
List:
["a", "b", "c", "are the letters"]
"a b c are the letters" 0
List:
["1", "2", "3"]
"123" 123
List:
[1, 2, 3]
"1 2 3" 0
List:
[1, 22, 3]
"1 22 3" 0
List:
["3", ".", "1", "4"]
"3.14" 3.14
List:
[3, ".", 1, 4]
"3 . 1 4" 0
List:
[]
"" 0