101.school
CoursesAbout
Search...⌘K
Generate a course with AI...

    Python

    Receive aemail containing the next unit.
    • Refreshing Python Basics
      • 1.1Python Data Structures
      • 1.2Syntax and Semantics
      • 1.3Conditionals and Loops
    • Introduction to Object-Oriented Programming
      • 2.1Understanding Class and Objects
      • 2.2Design Patterns
      • 2.3Inheritance, Encapsulation, and Polymorphism
    • Python Libraries
      • 3.1Numpy and Matplotlib
      • 3.2Pandas and Seaborn
      • 3.3SciPy
    • Handling Files and Exception
      • 4.1Reading, writing and manipulating files
      • 4.2Introduction to Exceptions
      • 4.3Handling and raising Exceptions
    • Regular Expressions
      • 5.1Introduction to Regular Expressions
      • 5.2Python’s re module
      • 5.3Pattern Matching, Substitution, and Parsing
    • Databases and SQL
      • 6.1Introduction to Databases
      • 6.2Python and SQLite
      • 6.3Presentation of Data
    • Web Scraping with Python
      • 7.1Basics of HTML
      • 7.2Introduction to Beautiful Soup
      • 7.3Web Scraping Case Study
    • Python for Data Analysis
      • 8.1Data cleaning, Transformation, and Analysis using Pandas
      • 8.2Data visualization using Matplotlib and Seaborn
      • 8.3Real-world Data Analysis scenarios
    • Python for Machine Learning
      • 9.1Introduction to Machine Learning with Python
      • 9.2Scikit-learn basics
      • 9.3Supervised and Unsupervised Learning
    • Python for Deep Learning
      • 10.1Introduction to Neural Networks and TensorFlow
      • 10.2Deep Learning with Python
      • 10.3Real-world Deep Learning Applications
    • Advanced Python Concepts
      • 11.1Generators and Iterators
      • 11.2Decorators and Closures
      • 11.3Multithreading and Multiprocessing
    • Advanced Python Concepts
      • 12.1Generators and Iterators
      • 12.2Decorators and Closures
      • 12.3Multithreading and Multiprocessing
    • Python Project
      • 13.1Project Kick-off
      • 13.2Mentor Session
      • 13.3Project Presentation

    Refreshing Python Basics

    Understanding Python Syntax and Semantics

    general-purpose programming language

    General-purpose programming language.

    Python is a high-level, interpreted programming language known for its simplicity and readability. This article will provide a comprehensive overview of Python's syntax and semantics, including variables, operators, and data types.

    Python Syntax

    Python's syntax is clean and easy to understand, even for beginners. Here are some key aspects:

    • Indentation: Python uses indentation to define blocks of code. Each level of indentation is a block, and it starts with a colon (:) and ends when the indentation decreases.

    • Comments: Comments in Python start with a hash (#). Python will ignore these comments, and they are used to explain the code.

    • Statements: In Python, instructions written in the source code for execution are called statements. For example, a = 1 is an assignment statement.

    • Expressions: Expressions only contain identifiers, literals, and operators. Expressions need to be evaluated. If you ask Python to print an expression, it will write the result of the expression.

    Python Variables

    Variables in Python are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.

    • Declaration and Assignment: Variables are declared by assignment, using the equals sign (=). For example, x = 5.

    • Scope: The scope of a variable determines the portion of the code where you can access a particular identifier. There are two basic scopes of variables in Python - Global variables and Local variables.

    Python Operators

    Operators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand.

    • Arithmetic Operators: Python includes the standard arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), modulus (%), exponentiation (**), and floor division (//).

    • Comparison Operators: These operators compare the values on either side of the operand and determine the relation between them. They include equals (==), not equals (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=).

    • Logical Operators: Logical operators in Python are used for conditional statements are true or false. Logical operators in Python: and, or, not operators.

    • Bitwise Operators: Bitwise operators act on operands as if they were strings of binary digits. They operate bit by bit, hence the name.

    Python Data Types

    Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data.

    • Numeric: Python supports integers, floating-point numbers, and complex numbers. They are defined as int, float, and complex classes in Python.

    • Sequence Type: In Python, sequence is the ordered collection of similar or different data types. Sequences allows to store multiple values in an organized and efficient fashion. There are several sequence types in Python - String, List, Tuple.

    • Mapping Type: Python’s dictionary is a kind of hash table type. They work like associative arrays and consist of key-value pairs.

    • File: File is a named location on disk to store related information. It is used to permanently store data in a non-volatile memory (e.g., hard disk).

    • Class: Class is a user-defined prototype for an object that defines a set of attributes that characterize any object of the class.

    • Exception: Exception is a base class for all exceptions.

    Understanding Python's syntax and semantics is crucial for writing and understanding Python code. With this knowledge, you can write clear, logical code for small and large tasks alike.

    Test me
    Practical exercise
    Further reading

    Hey there, any questions I can help with?

    Sign in to chat
    Next up: Conditionals and Loops