Programming · StudentHub Lesson
Intro to Python
Get started writing your first Python programs, from print statements to basic input.
What you will learn
- Write and run a basic Python program
- Use print() to display output
- Use input() to accept user input
- Understand Python's simple, readable syntax
- Combine variables, conditionals, and loops in a small program
Watch the lesson
Python for Beginners – Full Course [Programming Tutorial] · freeCodeCamp.org
Watch on YouTubeTopic notes
Main Idea
Python is a beginner-friendly programming language known for its clean, readable syntax, making it a great first language.
Key Concepts
- print() displays output to the screen
- input() collects text input from the user
- Python uses indentation instead of braces to define code blocks
- Comments start with # and are ignored by Python
Definitions
- Interpreter: a program that runs Python code line by line
- Syntax: the rules governing how code must be written
- Comment: a note in code ignored by the interpreter, starting with #
Syntax
```python
This is a comment
name = input("What is your name? ")
print("Hello, " + name)
```
Examples
- A simple greeting program using input() and print()
- Combining a variable, an if statement, and a loop in one small script
Common Mistakes
- Mixing tabs and spaces, causing indentation errors
- Forgetting parentheses when calling print() or input()
- Not converting input() results (always strings) before math operations
Key concepts
Important terms
- Interpreter
- A program that executes Python code line by line
- Comment
- Text in code ignored by the interpreter, used for notes
Worked examples
Problem
Write a program that asks for a name and greets the user
- 1. name = input('What is your name? ')
- 2. print('Hello, ' + name)
Answer: Hello, <name>
Quick revision
- print() shows output on screen
- input() collects user text
- Indentation defines Python code blocks
- Comments start with #
- input() always returns a string
Check your understanding
Question 1 · Multiple choice
Which function displays text on the screen in Python?
Question 2 · Multiple choice
What symbol starts a comment in Python?
Question 3 · True or false
input() always returns a string, even if the user types a number.
Question 4 · Short answer
What does Python use instead of curly braces to define code blocks?
Question 5 · Short answer
Write code to print 'Hi there!'
Done with Intro to Python?
Sign in to save your progress across the library.