L1-L3
Lesson 1: Getting Started
Key Concepts
IDE: Integrated Development Environment, where code is written (e.g., Pycharm, Spyder, Thonny, Online GDB, Pyscripter).
Syntax: Arrangement of words and phrases to create well-formed sentences in a language.
Syntax Errors: A character or string incorrectly placed in a command or instruction that causes a failure in execution.
Run-Time Errors: Detected errors while the program is running.
Name Errors: When a variable or function is not found.
Commands and Functions
Print: Prints a string.
Input: Allows user to enter a string or integer.
Str: Turns an integer into a string (use only if integer is added to another string).
Example:
print("My grade in Chem is " + str(2))
Int: Identifies an integer.
Example:
x = 10 if isinstance(x, int): print("Integer") else: print("Not Integer")
Lesson 2: Functions (1)
Key Concepts
Function: A sub-program that performs a specific task.
Function Body: The block of code after the function header.
Def: The first word in the function header.
Colon (:): Must appear at the end of the function header.
Built-in Functions: Functions that come as part of Python.
Function Call: A special line that causes the flow of control to switch to the first line inside the function body.
Flow of Control: The sequence in which lines of code are executed.
Function Definition: A function header and a function body.
Modular Functions: Break tasks into smaller functions (e.g., drawing shapes or numbers like "365").
Lesson 3: Variables, Assignments, and Expressions
Key Concepts
Variables: Memory locations used to store data; named by the programmer.
Assignment Operator (=): The equal sign; it assigns the value on the right-hand side to the variable on the left-hand side.
Example:
sum = firstNumber + secondNumber
Expressions: Can be a literal value or a combination of values and operators (e.g.,
firstNumber + secondNumber
).Arithmetic Operators:
+
(Addition)-
(Subtraction)*
(Multiplication)/
(Division)
Variable Naming Rules
Start with a letter or underscore (_), not a digit.
Contain only letters, digits, or underscores (no spaces or special characters).
Be case-sensitive (ISBN and isbn are different).
Avoid reserved keywords like
print
ordef
.