Python Scripts and Statements: Definitions,
Uses, and Examples
1. print() Statement
Definition: A built-in Python statement used to display output on the screen.
Use: Used to show messages, values, or results of a program.
Example:
print("Hello, World!")
print(25)
print("Score:", 90)
2. input() Statement
Definition: A built-in Python statement used to get input from the user.
Use: Used to make programs interactive by accepting user data.
Example:
name = input("Enter your name: ")
age = input("Enter your age: ")
3. Assignment Statement (=)
Definition: A statement used to assign a value to a variable.
Use: Used to store data in variables.
Example:
x = 10
name = 'Erika'
4. If Statement
Definition: A conditional statement that runs code if a condition is true.
Use: Used for decision making.
Example:
age = 18
if age >= 18:
print('Adult')
5. For Loop Statement
Definition: A statement that repeats a block of code a specific number of times.
Use: Used for counting and looping through data.
Example:
for i in range(3):
print(i)
6. While Loop Statement
Definition: A statement that repeats code while a condition is true.
Use: Used when repetition depends on a condition.
Example:
x=0
while x < 3:
print(x)
x += 1
7. Break Statement
Definition: A statement that stops a loop immediately.
Use: Used to exit a loop early.
Example:
for i in range(5):
if i == 3:
break
8. Continue Statement
Definition: A statement that skips the current loop iteration.
Use: Used to skip specific values in a loop.
Example:
for i in range(5):
if i == 2:
continue
print(i)
9. Comment Statement
Definition: A non-executable line used to explain code.
Use: Used to make code easier to understand.
Example:
# This is a comment