Why Python?
Python can be used for...
- Charts & Graphs
- Business
- Math
- Basic calculations - like a calculator
- Science, including biology, chemistry, physics
- Web sites or web development
- Very quick websites
- Large Enterprise scale websites
- Machine learning
- Artificial intelligence
- Deep learning
- Reinforcement learning
- 2D Graphics
- 3D Graphics
- Video Games - Python is a great way to learn about video games
- Unreal Engine - Python can be used in this professional level game development tool
Myth: Computer programming requires advanced schooling or training.
Fact: Anyone and everyone can learn how to program with Python.
Code Example
# Prints whole numbers and decimal numbers
print(10)
print(2.5)
Instructions
▲ ← Click the triangle to hide or reveal instructions.- The code editor is below.
- The left side of the code editor is where you type your input code.
- The right side of the code editor is where you see the output of your code.
- Practice by typing the code example above, in the left side of the code editor below.
- Then click the "Run Code" button, to run the code.
- You will see the output of your code in the output section.
Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- If you want to write the number 10 on the screen all you need to do is use the print command.
- All you need to do is type: print(10),
- That's it, that easy.
- The
print() function is the standard way to send data to the screen in Python. - Sending data to the screen is called standard output.
- Passing the number
10 without quotes tells Python to process it as a number instead of text. - Passing
2.5 demonstrates Python's ability to handle decimal numbers automatically. - Python internally converts numerical values into a text format so they can be displayed visually.
- Every
print() call automatically adds a line break, which is why your results appear on two separate lines. - You can print multiple items at once by separating them with commas, such as
print(10, 2.5).
Code Example
# Prints text
print("Hello, how are you!")
print("Welcome to Python!")
Instructions
▲ ← Click the triangle to hide or reveal instructions.- The code editor is below.
- The left side of the code editor is where you type your input code.
- The right side of the code editor is where you see the output of your code.
- Practice by typing the code example above, in the left side of the code editor below.
- Then click the "Run Code" button, to run the code.
- You will see the output of your code in the output section.
Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Any text can displayed, just like a text message.
- Text requires that you start with double quotes " and end with double quotes ".
- Text can also start with a single quote ' and end with a single quote '.
- What if I want to display a single quote ' or a double quote " ?.
Code Example
# Prints words and sentences
print("I want to display a '")
print('Now I want to display a "')
print("I want to display single quotes 'testing'")
print('Now I want to display double quotes "testing"')
Instructions
▲ ← Click the triangle to hide or reveal instructions.- The code editor is below.
- The left side of the code editor is where you type your input code.
- The right side of the code editor is where you see the output of your code.
- Practice by typing the code example above, in the left side of the code editor below.
- Then click the "Run Code" button, to run the code.
- You will see the output of your code in the output section.
Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- To display a single quote ' or single quotes surround the text with double quotes "".
- To display a double quote ' or double quotes surround the text with single quotes ''.
- Text can also start with a single quote ' and end with a single quote '.
- What if I want to display a single quote ' or a double quote " ?.
Code Example
# Display single quotes and double quotes
print("I don't want to go inside")
print()
print('I may want to say "Thank you."')
Instructions
▲ ← Click the triangle to hide or reveal instructions.- The code editor is below.
- The left side of the code editor is where you type your input code.
- The right side of the code editor is where you see the output of your code.
- Practice by typing the code example above, in the left side of the code editor below.
- Then click the "Run Code" button, to run the code.
- You will see the output of your code in the output section.
Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Double quotes let you write a sentence that has a single quote inside it, like in the word don't.
- Single quotes let you write a sentence that has double quotes inside it, like when someone says "Thank you."
print() shows the message on the screen exactly as you type it inside the quotes.- You can use either single or double quotes in Python, as long as they match at the start and end.
Code Example
# Display numbers and strings
print(10, 2.5, "Hello")
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- You can use
print to show whole numbers, decimal numbers, and words on your screen. - Python is smart enough to know if you are giving it a number or a piece of text.
- When you put several things inside the parentheses, Python will show them all in a row.
- You can also use
print on just one thing at a time to show it on its own line.
Code Example
# Display numbers and strings
print(10,end="")
print(15,end="")
print("Hi")
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
print() normally moves to a new line after it shows something.- When you use
end="", it tells Python not to move to a new line. - This makes the next
print() show its output right next to the previous one. - In this example, the numbers and the word appear together on the same line.
Code Example
# Display blank lines
print("Hi",end="\n\n")
print("Hello",end="\n\n")
print("Good Morning")
print(10)
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Normally, Python starts a new line right after it finishes printing something.
- Adding
end="\n\n" tells Python to push the next bit of text further down the screen. - It works like pressing the "Enter" key twice on your keyboard to create a bigger gap.
- This is a great way to make your information look neat and spread out so it's easier to read.
Code Example
# Display blank lines
print("Hi")
print()
print("Hello")
print()
print(15)
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Using three quotes
""" lets you write a long message that covers many lines. - It is like writing a letter or a poem where you want to start a new line whenever you like.
- Python remembers exactly where you hit the "Enter" key and keeps those gaps in your message.
- When you
print the message, it looks on the screen exactly how you typed it in your code.
Code Example
message = """Hello,
This is a multiline
string in Python."""
print(message)
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Triple quotes
""" """ let you write text on more than one line. - You can press Enter inside the triple quotes to create new lines.
- When you use
print(), Python shows the text exactly the way it is written. - This is useful for things like addresses, letters, or lists that need to appear on separate lines.
Code Example
address = """John Smith
123 Main Street
New York, NY 10001
USA"""
print(address)
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Triple quotes
""" """ let you write text on many lines without using lots of print() statements. - You can press Enter inside the triple quotes to create a neat layout, like a menu.
- When you use
print(), Python shows the text exactly how it is written inside the triple quotes. - This makes it easy to display things like menus, lists, or signs in a clear way.
Code Example
menu = """Restaurant Menu
-------------
1. Burger
2. Pizza
3. Salad
4. Pasta"""
print(menu)
Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Click "Run Code" to see the output here
- Triple quotes
""" """ let you write text on many lines without using lots of print() statements. - You can press Enter inside the triple quotes to create a neat layout, like a menu.
- When you use
print(), Python shows the text exactly how it is written inside the triple quotes. - This makes it easy to display things like menus, lists, or signs in a clear way.