Python code important topic
Lesson 1: Introduction to Python
Python is beginner-friendly, readable, and widely used in web, data science, automation, and
more.
Code is written in plain text, executed line-by-line.
Example:
print("Hello, world!")
Lesson 2: Output & Print
Statement
Use print() to display output.
You can print text, numbers, and do basic math inside print.
print("Hi")
print(2 + 3)
print("Age:", 12)
Lesson 3: Strings & Numbers
Strings are text in quotes: "Hello", 'World'.
Numbers: Integers (5) and Floats (3.14).
Concatenation:
print("Hello " + "world")
Use * to repeat strings: "Hi" * 3 "HiHiHi" ←
Lesson 4: Variables
Store values with =.
name = "L"
age = 13
Variable names: letters, numbers, underscores no spaces or starting with numbers.
Lesson 5: Input & Type Conversion
input() gets user input (always as a string).
name = input("What's your name?")
Convert input:
age = int(input("Enter age: "))
Lesson 6: Basic Math Operations
+, -, *, /, ** (exponent), %
(modulus), // (floor division).
print(10 // 3) #
←3
print(2** 3) # 8 ←
Lesson 7: Strings Continued
Use \n for newline, \t for tab.
String methods:
print("hello".upper()) # HELLO
print("Hi".lower())
print("abc".replace("a", "z"))
Lesson 8: Comments
Use # for single-line comments.
Use or for multi-line comments.
# This is a comment
'''This is a multi-line comment''’
Lesson 9: Booleans &
Comparisons
Boolean values: True, False
Comparisons:
==, !=, >, <, >=, <=
● Example:
print(5 > 2) # ← True
A piece of text is called a string
Strings require quotation marks
The print() statement is used to send a value to the screen
You can add comments to your code with the hash symbol #
Python is a case-sensitive language
Snake case is the best practice
when creating multi-word variable names
computers store and process different data types differently
string is the data type for text
integer and float are data types for numbers
inputs and outputs help
machines communicate with the outside world
the input() instruction allows the user to enter a value into your program
the print() instruction is used to generate an output
Numerical values can be stored in variables
You can access the value stored in a variable by calling its name
Numerical data should not be surrounded by quotation marks
You can run calculations using the values stored in variables
You can store the result of a calculation in a variable
Updating the value of a variable is called reassigning a variable
Spaces are not allowed in variable names
A variable name cannot start with a number
Best practices can help you avoid errors
Errors in code are known as bugs
Code is executed line by line from top to bottom
Code execution is interrupted by bugs
the type() instruction is used to check the data type
the division of two integers always produces a float
Notes
Computer programs use
variables to remember important information
A variable has a name and a value
You can create a variable by connecting the name and the value with an equal sign =
inputs and outputs help
machines communicate with the outside world
the input() instruction allows the user to enter a value into your program
*the print() instruction is used to generate an output
Computer programs use
variables to remember important information
A variable has a name and a value
You can create a variable by connecting the name and the value with an equal sign =
humans use code to give instructions to machines
the print() instruction displays a message on the screen
you can use explicit data type conversions to avoid bugs in your programs
int() ensures that the user input is treated as an integer number
str() can help you concatenate numbers with text