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

Python

The document provides an overview of Python, highlighting its characteristics as a high-level, interpreted, and portable language with a rich library. It covers execution modes, keywords, data types, operators, input/output, type conversion, debugging, functions, and data structures such as strings, lists, tuples, and dictionaries. Additionally, it explains the syntax for user-defined functions, variable scope, and module usage.

Uploaded by

daewik69
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 views3 pages

Python

The document provides an overview of Python, highlighting its characteristics as a high-level, interpreted, and portable language with a rich library. It covers execution modes, keywords, data types, operators, input/output, type conversion, debugging, functions, and data structures such as strings, lists, tuples, and dictionaries. Additionally, it explains the syntax for user-defined functions, variable scope, and module usage.

Uploaded by

daewik69
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
You are on page 1/ 3

PYTHON

1. Introduction to Python

 High-level Language: Easy to understand and write.

 Interpreted: Executed line by line.

 Case-sensitive: NUMBER and number are different.

 Portable: Runs on various operating systems.

 Rich Library: Predefined functions for various tasks.

2. Execution Modes

 Interactive Mode: Execute one line at a time.

 Script Mode: Write and execute multiple lines in a file.

3. Python Keywords and Identifiers

 Keywords: Reserved words with specific meanings (e.g., if, else, for).

 Identifiers: Names given to variables, functions, etc. Rules:

o Start with a letter or underscore.

o Can contain letters, digits, or underscores.

o Cannot be a keyword.

4. Variables and Data Types

 Variables: Store data values.

 Data Types:

o Numbers: int, float, complex.

o Sequences: str, list, tuple.

o Sets: Unordered collection of unique elements.

o Dictionaries: Key-value pairs.

5. Operators

 Arithmetic: +, -, *, /, %, //, **.

 Relational: ==, !=, >, <, >=, <=.

 Logical: and, or, not.

 Assignment: =, +=, -=, *=, /=, %=, //=, **=.

 Membership: in, not in.


 Identity: is, is not.

6. Input and Output

 Input: input() function to take user input.

 Output: print() function to display output.

7. Type Conversion

 Explicit: Manually convert data types using functions like int(), float(), str().

 Implicit: Python automatically converts data types during operations.

8. Debugging

 Syntax Errors: Mistakes in code structure.

 Logical Errors: Code runs but produces incorrect results.

 Runtime Errors: Errors during execution (e.g., division by zero).

Functions in Python

1. Introduction to Functions

 Definition: A block of code that performs a specific task.

 Advantages:

o Increases code readability.

o Reduces code duplication.

o Enhances reusability.

2. User-Defined Functions

 Syntax:

def function_name(parameters):

# Function body

return value

 Arguments and Parameters: Values passed to a function during a call.

 Return Statement: Returns a value from the function.

3. Scope of Variables

 Global Variables: Accessible throughout the program.

 Local Variables: Accessible only within the function.

4. Built-in Functions

 Examples: len(), type(), input(), print(), sum(), min(), max().


5. Modules

 Definition: A file containing Python code (functions, variables, etc.).

 Importing Modules: Use import module_name to use functions from a module.

Strings, Lists, Tuples, and Dictionaries

1. Strings

 Definition: Sequence of characters enclosed in quotes.

 Operations: Concatenation (+), repetition (*), slicing ([start:end]), membership (in, not in).

 Methods: len(), lower(), upper(), strip(), split(), replace().

2. Lists

 Definition: Ordered, mutable sequence of elements.

 Operations: Concatenation, repetition, slicing, membership.

 Methods: append(), extend(), insert(), remove(), pop(), sort(), reverse().

3. Tuples

 Definition: Ordered, immutable sequence of elements.

 Operations: Concatenation, repetition, slicing, membership.

 Methods: count(), index().

4. Dictionaries

 Definition: Unordered collection of key-value pairs.

 Operations: Accessing values using keys, adding/updating key-value pairs, deleting keys.

 Methods: keys(), values(), items(), get(), update(), pop().

You might also like