Syntax Reference
Look things up here when you cannot remember a piece of syntax while studying or writing code. Each page has a short explanation, examples you can run right away and the common mistakes.
Python
- Python break vs continuebreak ends the loop; continue skips only the current iteration
- Python Dictionary (dict): Keys and ValuesLook up and change values by key, handle missing keys, loop, count
- Python enumerate(): Loop with Index and ValueGet the index and the value together as you loop
- Python f-string: Format Numbers and TextPut values inside a string: decimal places, width, alignment
- Python for LoopLoop over the values in a list or string one at a time
- Python input(): Read User InputRead one line of keyboard input, convert it to a number, read several lines
- Python join(): Join a List into a StringJoin a list of strings into one string with a separator
- Python List append(), extend() and insert()Add values to a list with append, extend and insert
- Python: Remove Duplicates from a ListDrop duplicates with set, or keep the original order with dict.fromkeys
- Python sort() vs sorted(): Sort a ListThe difference between sort and sorted, and choosing the order with key and reverse
- Python print(): Output with sep and endPrint values to the screen: several values, sep, end
- Python range(): Start, Stop and StepFrom 0 to n-1, start, stop and step, counting backwards
- Python Slicing: [start:stop:step] ExplainedCut a piece out of a string or list with [start:stop:step]
- Python split(): Split a String into a ListCut a string at a separator and get a list
- Python while LoopRepeat while a condition is true, while True and an end marker
C
- C Arrays: Declare, Initialize, and LoopHandle several values of the same type by index
- C for LoopLoops with a known count: initializer, condition, update
- C if Statement: if, else if, elseBranch on a condition: if, else if, else
- C malloc() and free(): Dynamic MemoryAllocate memory while the program runs and give it back
- C Pointers Explained for BeginnersVariables that hold addresses: &, *, passing to functions, and arrays
- C printf(): Format Specifiers and OutputFormat specifiers %d %f %s %c, plus width and precision
- C scanf String Input: %s and fgets%s reads one word; use fgets for a whole line with spaces
- C scanf(): Read InputRead input into variables: &, several values, the return value
- C Strings: char Arrays, strlen, strcpy, strcmpchar arrays and the end marker, strlen, strcpy, strcmp
- C struct: Define and Use StructuresGroup related values into one unit: struct, typedef, ->
- C switch Statement: case, break, defaultCompare one value with several cases: case, break, default
- C while Loop and do-whileRepeat while a condition is true: while and do-while