Home Backend Development Python Tutorial Detailed explanation of basic syntax in python3

Detailed explanation of basic syntax in python3

Jul 27, 2017 pm 02:44 PM
python3 Base

1. Encoding

By default, python3 source files are encoded in UTF-8, and all strings are unicode strings. Of course, you can also specify different encodings for the source code files:

1 # -*- coding: gbk -*-
Copy after login

2. Identifier

1. The first character must be a letter or an underscore '_'.

2. The other parts of the identifier consist of letters, numbers and underscores.

3. Identifiers are case-sensitive.

In python3, non-ASCII identifiers are also allowed.

3. Python reserved words

Reserved words are keywords, and we cannot use them as any identification names. Python's standard library provides a keyword module that can output all keywords of the current version:

>>> import keyword>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']>>>
Copy after login

4. Comments

#   Single-line comments

''' or """ Multi-line comments, three single (double) quotation marks appear in pairs, you can also use this symbol to represent a piece of content

5. Lines and abbreviations

The most distinctive feature of Python is the use of indentation to represent the structure of a code block. The number of indented spaces is variable, but the same number of indented spaces must be used within the same code block.

6. Data types

Python data types include

Numbers (numbers)

String (strings)

List (List)

Tuple (Tuple)

Sets (Set)

Number type:

Number type classification: Integers, long integers, floating point numbers and complex numbers

Integer: 1

Long integer: It is a relatively large integer

Floating point: 1.23 3E-2

  Plural numbers: 1 + 2j, 1.1 + 2.2j

String:

* Single quotes and double quotes are used exactly the same in Python

. * Use triple quotes (''' or """) to specify a multi-line string.

Escape character '\'

Natural characters, by adding r or R before the string. For example,

print(r"this is a line with \n") displays the result: this is a line with \n

The string is immutable

literally Concatenated strings such as

>>> a = "this " "is " "string">>> a'this is string'
Copy after login


The above is the detailed content of Detailed explanation of basic syntax in python3. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP Basics Tutorial: From Beginner to Master PHP Basics Tutorial: From Beginner to Master Jun 18, 2023 am 09:43 AM

PHP is a widely used open source server-side scripting language that can handle all tasks in web development. PHP is widely used in web development, especially for its excellent performance in dynamic data processing, so it is loved and used by many developers. In this article, we will explain the basics of PHP step by step to help beginners from getting started to becoming proficient. 1. Basic syntax PHP is an interpreted language whose code is similar to HTML, CSS and JavaScript. Every PHP statement ends with a semicolon; Note

Can I learn Linux from scratch? What do I need to learn? Can I learn Linux from scratch? What do I need to learn? Feb 19, 2024 pm 12:57 PM

If you want to work in the IT industry, but do you want to learn programming, which technology should you choose? Of course it is Linux operation and maintenance. Linux is a very popular technology on the market, with a wide range of applications and good employment prospects, and is liked by many people. So the question is, can I learn Linux operation and maintenance with zero basic knowledge? In the server market, Linux system has a market share of up to 80% because of its advantages such as stability, security, free open source, efficiency and convenience. From this, it can be seen that Linux applications are very popular. Extensive. Whether now or in the future, learning Linux is a very good choice. As for whether it is possible to learn from scratch? My answer is of course. Oldboy Education Linux face-to-face class is specially designed for people with zero basic knowledge

Introduction to PHP Basics: How to use the echo function to output text content Introduction to PHP Basics: How to use the echo function to output text content Jul 30, 2023 pm 05:38 PM

Basic introduction to PHP: How to use the echo function to output text content. In PHP programming, you often need to output some text content to a web page. In this case, you can use the echo function. This article will introduce how to use the echo function to output text content and provide some sample code. Before starting, first make sure you have installed PHP and configured the running environment. If PHP is not installed yet, you can download the latest stable version from the PHP official website (https://www.php.net).

Learn the basics of Go language variables Learn the basics of Go language variables Mar 22, 2024 pm 09:39 PM

Go language is a statically typed, compiled language developed by Google. Its concise and efficient features have attracted widespread attention and love from developers. In the process of learning the Go language, mastering the basic knowledge of variables is a crucial step. This article will explain basic knowledge such as the definition, assignment, and type inference of variables in the Go language through specific code examples to help readers better understand and master these knowledge points. In the Go language, you can use the keyword var to define a variable, which is the format of the var variable name variable type.

Detailed explanation of C language functions: basic to advanced, comprehensive analysis of the use of functions Detailed explanation of C language functions: basic to advanced, comprehensive analysis of the use of functions Feb 18, 2024 pm 02:25 PM

C language function encyclopedia: from basic to advanced, detailed explanation of how to use functions, specific code examples are required Introduction: C language is a widely used programming language, and its powerful functions and flexibility make it the first choice of many developers. In C language, function is an important concept. It can combine a piece of code into an independent module, improving the reusability and maintainability of the code. This article will introduce the use of C language functions from the basics and gradually advance to help readers master the skills of function writing. 1. Definition and calling of functions in C

How to install pip in python3 How to install pip in python3 Dec 20, 2023 pm 05:42 PM

Installation steps: 1. Make sure that Python3 has been installed and can be accessed through the command line; 2. Open the terminal and enter the "python3 -m ensurepip --upgrade" command to install pip; 3. Download the pip installation package from the official Python website; 4. Extract the downloaded pip installation package into a directory; 5. Open the terminal and navigate to the decompressed pip directory; 6. Run the "python3 setup.py install" command to install pip.

PHP study notes: Basics of object-oriented programming PHP study notes: Basics of object-oriented programming Oct 09, 2023 pm 12:46 PM

PHP study notes: Basics of object-oriented programming, specific code examples are required Introduction: Object-Oriented Programming (OOP for short) is a programming way of thinking that decomposes the problem into multiple objects and defines the interaction between objects. to solve complex programming problems. As a powerful programming language, PHP also supports object-oriented programming. This article will introduce the basic concepts and common syntax of object-oriented programming in PHP, and provide specific code examples. kind

PHP study notes: basic syntax and variable definition PHP study notes: basic syntax and variable definition Oct 09, 2023 am 08:03 AM

PHP study notes: basic syntax and variable definition In today's Internet era, PHP (Hypertext Preprocessor), as a widely used server scripting language, is favored by more and more developers. This article will introduce you to the basic syntax of PHP and the definition of variables, and provide specific code examples to help beginners better understand and master it. 1. Basic syntax of PHP Markings of PHP code In PHP code, we often use "<?php" and "?&

See all articles