Bioinfo Lab

Bioinformatics Laboratory at BiUH.

Core Values: Respect, Reflection, Communication, Commitment.

Main Page   |   Util & Src   |   Contact


Loading......

Password

Python Basics

  • Python has two execution modes: interactive mode and script mode. Interactive mode is good for quick testing, while script mode is suitable for complex programs.

  • In interactive mode, “exit()” is used to exit python3

  • In script mode, “python3” is used to run python3 script

  • Python syntax emphasizes indentation, typically using 4 spaces as the standard.

  • Python supports single-line comments (#).

  • Reserved keywords in Python (such as if, else, while) cannot be used as variable names or function names.

  • Common Python syntax errors include NameError, IndentationError, and TypeError.

  • Variable naming rules: Cannot start with a number, can only contain letters, numbers, and underscores.

  • Python is a dynamically typed language, allowing variables to be rebound to objects of different types at runtime.

  • Core data types in Python include integers, floating-point numbers, strings, and booleans.

  • Use the type() function to check the type of a variable, and functions like int(), float(), str() for type conversions.

  • Python has six types of operators: arithmetic operators (+, -, *, /, //, %, **), comparison operators (>, <, ==, !=, etc.), logical operators (and, or, not), assignment operators (=, +=, -=, etc.), identity operators (is, is not), and membership operators (in, not in).

  • Operator precedence determines the order of expression evaluation, and parentheses can change the precedence. For example, calculate expressions inside parentheses first, then evaluate other operators from highest to lowest precedence.

  • Strings support indexing and slicing operations. You can access characters in a string using indices, and slicing can extract substrings. Index of a string starts from 0.

  • Python provides a rich set of string methods, such as split() (to split strings), join() (to concatenate strings), strip() (to remove leading and trailing whitespace), find() (to search for substrings), index() (to search for substrings, raises an exception if not found), lower() (to convert to lowercase), upper() (to convert to uppercase), title() (to capitalize the first letter of each word), etc.

  • There are multiple ways to format strings. For beginners, use “aaa”+”bbb” to get “aaabbb”.