Page cover image

📗Python Definitions

Python, being a dynamically typed language, offers a variety of value types (data types) and keywords that are integral to its programming structure. Here's a list of some common value types and keywords along with their definitions:

Value Types (Data Types)

  1. int: Represents integer values. Example: 5, -3.

  2. float: Represents floating-point numbers (decimals). Example: 3.14, -0.001.

  3. str: String type for text. Example: "Hello", 'Python'.

  4. bool: Boolean type, representing True or False.

  5. list: An ordered, mutable (changeable) collection of items. Example: [1, 2, 3], ['a', 'b', 'c'].

  6. tuple: An ordered, immutable collection of items. Example: (1, 2, 3), ('a', 'b', 'c').

  7. dict: Dictionary type, an unordered collection of key-value pairs. Example: {'name': 'Alice', 'age': 25}.

  8. set: An unordered collection of unique items. Example: {1, 2, 3}.

  9. NoneType: Special type representing the absence of a value or a null value. Example: None.

Keywords

  1. def: Used to define a function. Example: def my_function():.

  2. return: Used to return a value from a function.

  3. class: Used to define a class.

  4. import, from: Used to import modules or specific functions, classes, etc., from modules.

  5. as: Used in import statements to give an imported module a different alias, or with try...except blocks to rename exceptions.

  6. if, elif, else: Conditional statements.

  7. for, while: Loop control statements.

  8. break: Exits a loop.

  9. continue: Skips the current iteration in a loop.

  10. try, except, finally, raise: Exception handling keywords.

  11. with: Used for exception handling in resource management (like file reading/writing).

  12. global: Declares a variable as global.

  13. nonlocal: Declares a variable as non-local (useful in nested functions).

  14. lambda: Used to create an anonymous function.

  15. yield: Used in a function like return, but for generator functions.

  16. del: Deletes an object.

  17. pass: A null statement, a placeholder for future code.

  18. assert: Used for debugging purposes to check conditions that should always be True.

  19. in, not in: Membership operators.

  20. is, is not: Identity operators.

Last updated