By the end of this lesson, you will be able to:
print()
input()
:information_source: Info Definition: Python is a programming language with syntax rules for writing what is considered valid Python code.
Python is now one of the most popular programming languages. Data scientists use it for analyzing data and creating visualizations.
Python is a high-level programming language. This means you need fewer lines of code to complete tasks. It's perfect for beginners to learn!
Every programming language shares similar concepts. If you know another programming language, you'll find Python easier to learn.
:memo: Note Fun Fact: Guido van Rossum created Python and released it in 1991. He named it after the comedy group "Monty Python"!
Python helps you:
Python is different from other programming languages:
Feature | Python | Other Languages |
---|---|---|
Readability | Looks like English with math symbols | Often harder to read |
Commands | New lines separate commands | Use semicolons ; or parentheses () |
Code blocks | Use indentation (tabs) | Use curly brackets {} |
:bulb: Python's simple syntax makes it easier to focus on solving problems instead of memorizing complex rules!
:emoji: Making Python Talk with Print()
The
print()
function makes Python display text on your screen. It's one of the most important tools you'll use!How to use print():
- Type
print()
- Put your text inside the parentheses
- Wrap your text in "double quotes"
python
print("Hello World!")
- Click on the run button to see the text.
Hello World!
Creating New Lines
To move text to the next line, use
\n
(which stands for "new line"):python
print("Hello\nWorld!")
Hello World!
Joining Text Together
You can combine text in two ways:
Method 1: Using the + sign
python
print("Hello " + "World!")
Hello World!
Method 2: Using commas
:memo: Note Using commas automatically adds a space between your text!
python
print("Hello", "World!")
Hello World!
:emoji: Getting User Input with Input()
The
input()
function lets Python ask questions and wait for answers. This makes your programs interactive!How to use input():
- Type
input()
- Put your question inside the parentheses
- Wrap your question in "double quotes"
python
input("What is your name? ")
- Click on the run button to ask the question and wait for an answer.
csharp
What is your name?
When you type an answer, Python shows it but doesn't remember it:
csharp
What is your name? John
Saving Answers with Variables
To save the answer for later use, store it in a variable:
python
name = input("What is your name? ")
Now you can use the saved answer anywhere in your program! For example, to greet someone personally:
python
name = input("What is your name? ") print("Hi,", name)
csharp
What is your name? John Hi, John
:memo: Summary
In this lesson, you learned:
- Python is a beginner-friendly programming language
print()
displays text on the screeninput()
asks questions and gets answers- Variables store information for later use
:emoji: Video Tutorial
:emoji: Practice with AI
Code with AI: Try using AI to work with variables and data types.
Prompts to try:
- "Write a Python program that prints 'Hello, world!'"
- "Write a Python program that asks for my name and greets me personally."
- "Create a Python program that asks for my favorite color and responds with a compliment about it."
- "Write a program that asks for two numbers and prints their sum." tip Don't be afraid to experiment! Change the code AI gives you and see what happens.