"Python" Python basic Syntax encoding

Source: Internet
Author: User

    • Coding

By default, Python is encoded as UTF-8, and all strings are Unicode strings, and you can define different encodings for your code.

#coding: utf-8#or#-*-coding:utf-8-*-
    • Python reserved word

The reserved word is a keyword and cannot be used as any identifier name. View current version All keywords: keyword module

1 Import keyword    #导入keyword模块2 keyword.kwlist
[' False ', ' None ', ' True ', ' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' fi Nally ', ' for ', ' from ', ' global ', ' if ', ' Import ', ' on ', ' is ', ' LA
    • Comments

Single-line Comment: The line that begins with # in code is a comment, and the program does not execute the line when it executes

Multiline Comment: "" "Multiline Comment" "or" "Multi-line Comment"

#这是一个注释 "This is the second comment" "" "" This is the 3rd comment ""
    • Data type

Python has data types: Boolean, Integer, Long, float, string, list, tuple, dictionary, date

    1. Boolean (BOOL): True/false, 0 of any numeric value, empty string, empty list [], empty tuple (), empty dictionary {} are false, function or method return value is null with false, other data is True.
In [4]: bool (True) out[4]: Truein [5]: bool (False) out[5]: Falsein [6]: bool (0) out[6]: Falsein [8]: BOOL ([])       #空列表 out[8] : Falsein [9]: BOOL (())       #空元组Out [9]: Falsein []: bool ({})   #空字典Out [ten]: Falsein []: bool (1) out[12]: True .................
    1. Integer (int): Range -2**31 to 2**31-1, which exceeds this range for long integers
    2. String (str): Enclosed in quotation marks is a string.
#type (): View data type in [+]: type ("Hello World") out[13]: Strin [+]: type ("123") out[14]: str
    • Print () output

Standard output, print () The default output is newline, if you want to implement no line break, you need to add end= "" at the end

>>>print ("Hello world!", end= "", "Hello python!")       #不换行输出 >>>hello world! Hello python!

"Python" Python basic Syntax encoding

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.