Python self-learning log-basics (1) and python Basics

Source: Internet
Author: User

Python self-learning log-basics (1) and python Basics

From Understanding python to learning python, I experienced a long time of psychological struggle. People always have a natural fear of unknown things, but they are curious about the unknown. In the end, I opened this door and started to learn python.

Python is actually quite interesting. This article mainly introduces python in basic aspects.

1. installation.

I mainly learn python on windows. This document only introduces the installation points of python on windows.

1. Installation version. python has two versions on the official python website. 1, python2 2, python3

There are many differences between the two versions. Here, I use python3, and the subsequent code demonstration uses python3.

I will not go into details about the installation. Here I will check the two options, otherwise I need to set the environment variable myself later.

2. manually set Environment Variables

Right-click computer

--"Attribute

  --Advanced System settings

    --Advanced

      --Environment Variables

        --In the second content box, find a line with the variable name Path and double-click

            --> Append the Python installation directory to the variable value and separate it;

     For example: the original value; C: \ python27; remember that there is a semicolon before

Ii. Data Types

There are not many data types in python, so there should be several

1. string type, class <str> indicates a string

2. numeric type. class <float> indicates a floating point number (which is roughly counted as a decimal number, but floating point type is not just a decimal number) class <int> Integer type (python2 contains long integers and integers, not in python3)

3. boolean type, class <bool> indicates judgment, True: Indicates True, Flase: Indicates false

4. Also, list: list, tuples: tuple, set: set, dictionary: dict

After understanding this, you can learn the basic syntax.

3. Basic syntax

Before that, some basic knowledge will be expanded.

1. Note: explains the functions of the Code, which can be divided into single-line and multi-line annotations.

Single line comment: Use "#" to comment before the content you want to comment. This line of content will not be executed in the code you write.

Multi-line comment: add three quotation marks before and after the content you want to comment. For example, '''hello '''. Comment multiple lines here, however, the example is represented by a row, which should be clear. These lines will not be executed in the code you write.

2. Variable: assign a literal constant to a meaningful symbol, which is the variable name.

Naming rules:

The variable name must start with a letter or underscore (including letters, numbers, and underscores)

It cannot be a keyword (Keyword: a meaningful English name in python)

The variable name cannot start with a number.

Note: The variable points to the memory address, and the new variable name points to the memory address of the variable.

(Chinese can be used as the variable name in python3, but it is not recommended .)

3, Operator

Operators in python follow the mathematical algorithm.

For composite operations and relational operations, we can see in subsequent code that the meaning of this operation can be understood in combination with the code.

Here we can start the simplest code learning:

# Coding: UTF-8

Print ('Hello word ')
Note: Remember to declare the file encoding of your script file before writing the code: in general, it will be declared as UTF-8
This line of code indicates printing 'Hello word'
This is the first piece of code to be practiced at the beginning of learning.
Next we will learn the commands and statements.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.