Traditionally, the first program written in a new language is called Hello, World! because all it does is display the words, Hello, World! In Python, the source code looks like this.
Some people judge the quality of a programming language by the simplicity of the Hello, World! program. By this standard, Python does about as well as possible.
This is an example of using the print function, which doesnβt actually print anything on paper. It displays a value on the screen. In this case, the result is the phrase:
The print("Hello, World!") statement in Python outputs the text "Hello, World!" to the screen. The quotation marks (" ") within the code define the start and end of a string value, which is a sequence of characters enclosed in quotes. The quotation marks tell Python that everything inside them should be treated as text, not code. When we run this code, Python displays only the text content between the quotation marks, so the quotes themselves arenβt part of the output. This is why the result displayed on the screen is simply: Hello, World!
In Python, and in most programming languages, a string is a data type used to represent text, such as words, sentences, or any sequence of characters. Strings are created by enclosing text within quotation marks, either single (β β) or double (" "). For example:
"Hello, World!" # Using double quotes
'Alice' # Using single quotes
Strings are versatile and widely used, from displaying messages to handling user input. Python allows flexibility in defining strings, so single or double quotes can be used interchangeably. This flexibility is especially helpful if your string contains an apostrophe or quotation marks, as in "Itβs a beautiful day" or βShe said, "Hello!"β. Here is the example in activecode. Give it a try!