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

Python Guide

The Python Programming Guide covers essential topics including variables, data types, operators, input/output, conditionals, loops, collections, functions, classes, and error handling. It provides syntax examples, common mistakes, and best practices for writing Python code. Additionally, it includes information on libraries, debugging, and mini projects to enhance programming skills.

Uploaded by

mawibelmonte
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 views4 pages

Python Guide

The Python Programming Guide covers essential topics including variables, data types, operators, input/output, conditionals, loops, collections, functions, classes, and error handling. It provides syntax examples, common mistakes, and best practices for writing Python code. Additionally, it includes information on libraries, debugging, and mini projects to enhance programming skills.

Uploaded by

mawibelmonte
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 Guide 3.

Variables

1. Introduction For every variable include:

 Program Structure: Python programs are sequences of statements,  Definition: Named storage for data.
functions, and classes. No explicit main() required.
 Syntax: x = 10
 Entry Point: Execution starts at the first line.
 Example:
 Comments: # single-line, triple quotes """ ... """ for
Code
docstrings.
name = "Alice"
 Identifiers: Names for variables/functions; case-sensitive.

 Keywords: Reserved words like if, else, def, class, return,


import. age = 25

 Memory Size: Dynamic, managed by Python.


2. Data Types  Range: Depends on type.
 int – whole numbers, unlimited size.  Default Value: None (must be assigned).
 float – decimal numbers (64-bit IEEE 754).  Common Mistakes: Mixing types, assuming fixed size.
 complex – numbers with real and imaginary parts (3+4j).

 str – text sequences. 4. Constants


 bool – True or False.  Python has no built-in const.
 list – ordered, mutable collection.  Convention: use UPPERCASE names (PI = 3.14159).
 tuple – ordered, immutable collection.  [Link] for symbolic constants.
 set – unordered, unique elements.

 dict – key-value pairs. 5. Operators


 NoneType – represents “no value”.  Arithmetic: +, -, *, /, //, %, **

 Comparison: ==, !=, <, >, <=, >=


 Logical: and, or, not  \f form feed

 Assignment: =, +=, -=, *=, /=  \v vertical tab

 Bitwise: &, |, ^, ~, <<, >>

 Unary: -x, +x 8. Input & Output

 Ternary: x if condition else y  print() – output.

 Precedence: Parentheses > Exponent > Multiplication/Division >  input() – user input (always string).
Addition/Subtraction > Comparisons > Logical.
 File I/O: open(), read(), write(), close().

 Context manager: with open(...) as f:.


6. Format Specifiers

 Old style: %d, %f, %s


9. Conditionals
 [Link](): "{} {}".format(a, b)
 if
 f-strings: f"{a} {b}"
 if-else
 Common mistakes: Mixing % and format().
 elif
7. Escape Sequences
 Nested if
 \n newline

 \t tab
10. Loops
 \\ backslash
 for – iterates over sequences.
 \" double quote
 while – repeats until condition false.
 \' single quote
 break, continue, pass.
 \b backspace
 Nested loops.
 \r carriage return
 Infinite loops (while True:).
 \a bell
11. Collections  Inheritance, polymorphism, encapsulation.

 Lists: [1,2,3]

 Tuples: (1,2,3) 15. Exceptions

 Sets: {1,2,3}  try, except, finally.

 Dictionaries: {"key":"value"}  Common: ValueError, TypeError, IndexError, KeyError.

 Raising: raise Exception("error").

12. Strings

Important functions: 16. Dynamic Memory

 len(), upper(), lower(), strip(), split(), join(), replace(),  Automatic garbage collection.
find(), startswith(), endswith().
 del keyword.

 Reference counting.
13. Functions

 Declaration: def func():


17. File Handling
 Parameters: positional, keyword, default.
 open(), read(), write(), close().
 Arguments: values passed.
 Context manager: with open(...) as f:.
 Recursion: function calling itself.

 Return values: return x.


18. Decorators
 Lambda functions: lambda x: x+1.
 Function decorators: @staticmethod, @classmethod.

 Custom decorators.
14. Classes & Objects

 class keyword.
19. Iterators & Generators
 __init__ constructor.
 iter(), next().
 Attributes & methods.
 yield keyword.  Comments & docstrings.

 Code organization (modules, packages).

20. Libraries

 Standard: math, random, datetime, os, sys, json, re. 24. Mini Projects

 External: numpy, pandas, matplotlib, requests.  Calculator

 ATM Simulation

21. Debugging  Student Record System

 Syntax Errors.  Bank System

 Runtime Errors.  Inventory Management

 Logical Errors.  Library System

 Using pdb.  Quiz Game

22. Common Errors

 IndentationError

 TypeError

 NameError

 IndexError

 KeyError

23. Best Practices

 Naming conventions (PEP 8).

 Indentation (4 spaces).

You might also like