Tuesday, February 27, 2024

 Writing your first Python program (Hello World!).


Let's start with some simple code to get a simple output (the information the program gives to the user).

print("Hello World!")

output
Hello World!

You just learned your first command: the print statement. It says "Print out whatever's in my brackets". The print statement is how you get your program to put messages in the console.

  • The " " (quotes) are used to tell the command that you're putting text in there (any text you want)
  • A bunch of text (or whatever you put in quotes) is called a string.

Multiple Print Statements

Here is what multiple print statements looks like. 

print("Well we")
print("just use more lines")
print("of code")

output
Well we
just use more lines
of code


Use the triple quote """ if you want to write a big chunk of text with gaps or line breaks. 

print("""Anything that starts
with three quotes, and ends
in three quotes can span
many lines and even contain " symbols
within it without freaking anything out!""")

Output
Anything that starts
with three quotes, and ends
in three quotes can span
many lines and even contain " symbols
within it without freaking anything out!




No comments:

Post a Comment

  2D Dictionaries Remember that dictionaries are very similar to lists, except that they store data as key:value pairs. The value is what it...