Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 2.02 KB

Python_03_Misc_Intro.md

File metadata and controls

32 lines (25 loc) · 2.02 KB

🐍 Misc. Introductory Topics 🧩

Table of Contents

  1. Comments in Python
  2. Getting Input from Users
  3. Try / Except Blocks
  4. Reading Files

Comments in Python

  • Purpose of Comments: Explains that comments are lines in Python code ignored during execution, used for notes or explanations.
  • Creating Comments: Demonstrates using the hashtag symbol (#) for single-line comments.
  • Multi-line Comments: Shows how to use triple quotes for multi-line comments, though the official Python style guide recommends using multiple hashtags.
  • Commenting Out Code: Discusses using comments to temporarily disable code for testing or debugging.

Getting Input from Users

  • Basic Input: Covers how to use the input() function to receive user input.
  • Storing Input in Variables: Demonstrates storing user input in variables for further use.
  • Example Application: Provides an example where the program asks for the user's name and age, then outputs a personalized message.

Try / Except Blocks

  • Error Handling: Introduces the concept of catching and handling errors using try/except blocks.
  • Specific Error Types: Shows how to handle specific types of errors like ValueError and ZeroDivisionError.
  • Storing Error as Variable: Demonstrates storing the error in a variable (err) for detailed error information.
  • Best Practices: Emphasizes the importance of catching specific errors rather than using a broad except clause.

Reading Files

  • Opening Files: Explains how to open files using the open() function with different modes ('r', 'w', 'a', 'r+').
  • Reading File Content: Shows methods to read the entire file content or individual lines using read() and readline().
  • Checking File Readability: Discusses using the readable() function to check if a file is readable.
  • Closing Files: Stresses the importance of closing files after reading to free up system resources.