Function print() in Dart
Let's take a detailed look at how to use the print()
function:
Print with Text
main.dart
123void main() { print("Text you want to output"); }
The program prints information to the console from the parentheses of the print()
function.
If we want to output the text to the console, we must write it inside the quotation marks.
main.dart
1234void main() { print('Hi, Codefinity!'); print("I want know more"); }
Rules
The text can be written in single quotation marks:
'Hi, Codefinity!'
The text also can be written in double quotation marks:
"I want know more"
The main rule when using the print()
function is that it's important for the quotation marks surrounding the text to match on both sides. For example, if we use single quotes to print text ('like this')
, we must close them with single quotes as well. This allows Dart to correctly recognize it as text to be printed, rather than a variable name or instruction. If the quotation marks do not match, or if they are absent altogether, it can lead to a runtime error in the program.
Print with Numbers
Working with numbers is different from working with text. Suppose you want to display numbers. Since we work with number values, you don't need to use quotes (" "
or ' '
).
main.dart
123void main() { print(2); }
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 4.55
Function print() in Dart
Scorri per mostrare il menu
Let's take a detailed look at how to use the print()
function:
Print with Text
main.dart
123void main() { print("Text you want to output"); }
The program prints information to the console from the parentheses of the print()
function.
If we want to output the text to the console, we must write it inside the quotation marks.
main.dart
1234void main() { print('Hi, Codefinity!'); print("I want know more"); }
Rules
The text can be written in single quotation marks:
'Hi, Codefinity!'
The text also can be written in double quotation marks:
"I want know more"
The main rule when using the print()
function is that it's important for the quotation marks surrounding the text to match on both sides. For example, if we use single quotes to print text ('like this')
, we must close them with single quotes as well. This allows Dart to correctly recognize it as text to be printed, rather than a variable name or instruction. If the quotation marks do not match, or if they are absent altogether, it can lead to a runtime error in the program.
Print with Numbers
Working with numbers is different from working with text. Suppose you want to display numbers. Since we work with number values, you don't need to use quotes (" "
or ' '
).
main.dart
123void main() { print(2); }
Grazie per i tuoi commenti!