0% found this document useful (0 votes)
3 views5 pages

Python Programming Reviewer

This document is a study guide for Python programming, covering fundamental concepts such as syntax, data types, operators, control structures, and common errors. It includes examples and practice questions to reinforce learning. Key topics include variables, functions, lists, dictionaries, and loops.

Uploaded by

isgianmyname
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Python Programming Reviewer

This document is a study guide for Python programming, covering fundamental concepts such as syntax, data types, operators, control structures, and common errors. It includes examples and practice questions to reinforce learning. Key topics include variables, functions, lists, dictionaries, and loops.

Uploaded by

isgianmyname
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON PROGRAMMING REVIEWER

Study Guide with Examples and Practice Questions

1. What is Python?
Python is a high-level, interpreted programming language known for its simple and
readable syntax. It is commonly used for web development, data analysis, artificial
intelligence, automation, game development, and scientific computing.

2. Basic Python Syntax


A simple Python program is: print("Hello, World!"). The print() function displays
information on the screen.

3. Comments
Comments are notes in code that Python does not execute. A single-line comment begins
with #.

Example: # This is a comment

4. Variables
A variable stores a value. Example: name = "Gian" and age = 18. Python is case-sensitive, so
age, Age, and AGE are different variables.

5. Data Types
String (str) – text, such as "Maria".

Integer (int) – whole numbers, such as 18.

Float (float) – decimal numbers, such as 99.50.

Boolean (bool) – True or False.

6. Checking Data Types


Use type() to determine the type of a value. Example: type(10) returns int.

7. Type Conversion
Common conversion functions are int(), float(), str(), and bool(). Example: age = int("18").
8. Input
Use input() to get information from the user. input() returns a string by default. To get a
number, use int(input(...)) or float(input(...)).

9. Arithmetic Operators
+ Addition

- Subtraction

* Multiplication

/ Division

// Floor division

% Modulus/remainder

** Exponent

10. Comparison Operators


== Equal to

!= Not equal to

> Greater than

< Less than

>= Greater than or equal to

<= Less than or equal to

11. Logical Operators


and – both conditions must be true.

or – at least one condition must be true.

not – reverses a Boolean value.

12. Conditional Statements


if executes code when a condition is true. elif checks another condition. else executes when
previous conditions are false. Python uses indentation to define code blocks.
13. Loops
for loops are useful for iterating over sequences or repeating a known number of times.
while loops repeat as long as a condition remains true.

14. Lists
A list stores multiple values and is ordered and changeable. Example: fruits = ["apple",
"banana", "orange"]. Python list indexing starts at 0. Common methods include append(),
remove(), and len().

15. Tuples
A tuple is an ordered collection whose elements cannot normally be changed after creation.
Example: colors = ("red", "green", "blue").

16. Sets
A set stores unique values and removes duplicates. Example: numbers = {1, 2, 3, 3, 4}.

17. Dictionaries
A dictionary stores data as key-value pairs. Example: student = {"name": "Gian", "age": 18}.
A value can be accessed using its key, such as student["name"].

18. Functions
A function is a reusable block of code. The def keyword defines a function. Parameters allow
a function to receive values, and return sends a value back.

19. break and continue


break stops a loop. continue skips the current iteration and moves to the next iteration.

20. Common Python Errors


SyntaxError – invalid Python syntax.

NameError – a variable or name does not exist.

TypeError – an operation uses incompatible types.

ValueError – a value has an inappropriate format or cannot be converted.


Code Examples
print("Hello, World!")

name = "Gian"
age = 18
print(name)
print(age)

age = int(input("Enter your age: "))

if age >= 18:


print("Adult")
else:
print("Minor")

for i in range(5):
print(i)

x = 1
while x <= 5:
print(x)
x += 1

def add(a, b):


return a + b

result = add(5, 3)
print(result)

Quick Memory Guide


Topic Remember
print() Displays output
input() Gets user input
int Whole number
float Decimal number
str Text
bool True/False
= Assignment
== Comparison
if / elif / else Decision making
for / while Loops
list Ordered, changeable collection
tuple Ordered, generally unchangeable collection
set Unique values
dict Key-value pairs
def Defines a function
return Sends a value back
break Stops a loop
continue Skips an iteration

Practice Questions
1. What is the output of print(5 + 3)?

Answer: 8

2. What is the result of 10 % 3?

Answer: 1

3. What data type is "Hello"?

Answer: str

4. What does == mean?

Answer: Equal to / comparison

5. What does len() do?

Answer: Returns the number of items or characters

6. What is the first index of a Python list?

Answer: 0

7. What keyword creates a function?

Answer: def

8. What does break do?

Answer: Stops the loop

9. What does input() return by default?

Answer: str

10. What are the two Boolean values?

Answer: True and False

Must Memorize
print(), input(), if / elif / else, for, while, def, return

Remember: = means assignment, == means comparison, and Python indexing starts at 0.

You might also like